Window resizing with constant aspect ratio

Godot Version

4.3 c#

Question

I have been attempting to achieve window resizing maintaining a constant aspect ratio in code and have also tried in the IDE. The window contents do not quite track the window. Is there a correct way to achieve accurate tracking?
Thank you.

Hi, this might be what you are looking for or at least get you started: Size and anchors — Godot Engine (stable) documentation in English

If you aren’t familiar with anchors / presets in godot, this could be part of the problem.

Edit: note that documentation may not be fully up to date for 4.3. Might need to use other sources in conjunction with it.

I am not sure this is a good idea unless you are doing something very special. It could be very annoying for users if you try to limit their control on window aspect ratio. It might even be impossible given the way windows work at least on a PC.

If you want to control the position of UI elements, control nodes and canvas layers are what you should use. They are very powerful but there is a learning curve on getting your head around how they work. Once you get the gist, they are amazing!

If it is because of some game limitations in your environments or worlds etc, you should pad out the empty space with something relevant (some use clouds, or starry space backgrounds, or walls or bricks etc.

Perhaps we could help more if we knew the problem you were trying to solve with a forced aspect ratio on a window.

PS I suppose your other choice would be to not have the window resizable at all. You can find this in the project settings. But again this could be annoying to many users.

What type of contents I suppose is the question.

1 Like

Thank you for your comments. On reflection I think you are absolutely right, the complication isn’t justified.

1 Like