#How to Make a 2D Platform Game Adapt to Different Display Resolutions in Godot 4?

2 messages · Page 1 of 1 (latest)

tribal pilot
#

I'm developing a 2D platform game using the Godot Engine, with a 4K resolution. I'm unsure about how to make the game adapt to different display resolutions, as I've noticed in my gaming experience that games often have different resolution settings. Is this something implemented within the game engine? If so, how can I achieve this?

Due to the game not being a traditional pixel game, all in-game numbers are quite large (my character is 256x256 pixels, for example; the gravity is currently set to 12000), which is causing me some confusion.

I'm considering setting up a getter function to calculate the world coordinates and pixel ratio based on the game's resolution when first accessed. Then, returning a constant (the ratio of world coordinates to pixels at different resolutions, referred to as a scaling constant). Afterwards, I would enforce the physics interface to multiply by this scaling constant, thus creating a physics interface based on world coordinates.

I came across the function get_pixels_per_meter() while searching for "pixel" and "meter" keywords. Can it help me obtain the current world's pixels per meter ratio?

Thank you!

mossy berry
# tribal pilot I'm developing a 2D platform game using the Godot Engine, with a 4K resolution. ...

I would recommend you to not write game code that is depending on your resolution.
My usual approach is to start developing with a resolution that is comfortable and has at least my target ratio (for instance steam deck 1280x800) and use Stretch mode canvas_items and some aspect setting to make one of the sizes fixed (keep_height leads to only width expanding).

When working with 2D environments then, you should work with a Camera2D to take advantage of zoom if higher resolutions make everything too small and vice versa.
If things get blurry when upscaled (like going for 1280x800 and then stretching to 4k), you can set texture import settings to import things in a larger scale (when working with svg for instance). I usually import svgs at 2 times or 4 times size, so everything looks crisp enough when scaling animations.

You want your game to behave the same regardless of the resolution I assume? This way your code is independent of it.