0 votes

Greetings Godot Community!

I am currently working on a small game which basically always has the same screen shown. No scrolling, moving, etc.

I now want to support different Resolutions (from FullHD and down, I don't think 2 or 4K is needed). I have read the Godot documentation about screen scalling, etc. and I played around with it, but I am not getting very far.

My current solution is seeting the stretchmode to 2D and the stretchaspect to keep. This works, but looks terrible.

See picture:


Thanks in advance!

in Engine by (71 points)

There are several ways to deal with resizing.

In my game I took the simplest, which is basically fixing the resolution to some value and stretching it by keeping aspect ratio, leading to potential black margins, but at least I can place things where I want and all will just stretch proportionally.

Another way is to play with Control anchors. As you can see, a control can be defined as 4 margins relative to its parent, and has 4 anchors for all these 4 directions.
These anchors can be "begin", "center", end". This actually tells Godot which reference to take in the parent rectangle for each margin.
For example, to center a label horizontally, you would set left and right anchors to "center" and set the left and right margins to zero, or something like -halfSize ; +halfSize.
Another example: to place a label on the bottom-right of the screen at a distance of 50 pixels, set its right and bottom anchors to "end", and respective margins to 50.
These anchors will be respected for any resolution changes, because they let you position your UI through rules instead of fixed positions.

On your screenshot, I see the background is only half-visible due to the resolution change. Is that intented?
In order to center it, you can either use a GUI node for it, or use a Camera that you center on it so that resolution changes will keep the view centered in the game world rather than the top-left point (often implies having the GUI on another layer though).

I didn't play much with complex resolution changes yet, so maybe other people who had this problem can help. It's possible that you could also use multiple layers scaling differently, or even use scripts if the game needs specific things to deal with scaling.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.