0 votes

Hello, I am trying to figure out how to center the game when the window is resized. From the windows settings I used "2d" and stretch "expand" settings. Is there any way to make it so that when expanded the game's insides will be centered to the center and not the top-left? Here's some images:

Normal:
Normal Size

Resized:
Resized

How can I make it so that the resized window's insides will be in the middle?

Godot version V3.3 Stable Mono
in Engine by (12 points)

3 Answers

0 votes

Assuming you're working with Control nodes, this is fairly easy. Make sure your root node is a container node, such as PanelContainer. Set the PanelContainer to expand to the full size of the viewport by setting its right and bottom anchor properties to 1 and setting the EXPAND size flags in both directions.

Then you can center other control nodes in that container by making use of the container's children anchor properties. For simple cases, it should be enough to set anchor values of 0.5 for the children.

You can also use the FILL (disable) and SHRINK_CENTER (enable) size flags for the children, for example to center a label.

OTOH, if you are working with 2D nodes, not control nodes, these won't automatically reposition themselves when you resize their parents. You'll need to write some code to reposition your nodes to your liking when you resize something. Again, it's easy if your root node is a control node, since control nodes provide a "resized" signal which you can connect to in order to be notified when the window geometry changes.

You should also check out the Godot manual, there's a chapter on dealing with different screen resolutions that might be helpful to you in case you're mainly worried about the application window being resized.

by (291 points)
0 votes

You may want to try using the aspect 'keep' window setting, which will keep your game view the same relative width and height as you expand it. This should keep your content centered, as no more of the game gets revealed if you increase the width or height – it just gets scaled instead.

by (28 points)
0 votes

So Your question is how to stop Godot make it's own resolution while the window is resized, To do that go in Project Settings/Display/Window/Stretch and in Aspect
choose Keep, by this way you can prevent Godot making it's own resolution to fit the resizing done by the User. Comment me if any more trouble or questions

by (14 points)

This is a fine solution, but what if someone has a different aspect ratio monitor? Or should I just ignore non-16:9 aspect ratio players? Does anyone even have that kind of aspect ratio anymore?

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.