0 votes

When the window resolution changes, I would like the margins to stay the same. Right now, if i adjust the window size, a part of the control node is cut off. I would like for the control node to readjust its size based on the margins. Changing how the screen expands will not work in this situation. All of my attempts so far have been unsuccessful.

Godot version 3.3.2
in Engine by (59 points)
edited by

2 Answers

0 votes

You need to make use of the anchor points — these four green pins:

Anchor Points
UI elements all move relative to their location.
If they are all together like this then your element will just translate:

Default — Top-RightCentered
Instead, dragging them around the corners of your UI element like this will anchor the element to its original position and resize it relative to the screen like you are wanting:

Anchor Points surrounding the UI element
 Anchored to the Original Position


You can read a little bit more about UI anchoring here:
https://docs.godotengine.org/en/latest/tutorials/ui/size_and_anchors.html

Hope that it helps! Good luck!

by (1,014 points)
edited by

Okay, I was able to do it through a process inspired by this post. basically, I put the anchor in the top right and then I just wrote some code:

marginright = getsetting("display/window/size/width") - desiredmargin
margin
bottom = getsetting("display/window/size/height") - desiredmargin

desired margin is a variable with your desired margin. If it is changed all margins have to be set. I'm just putting this here in the hopes that somebody else finds it and also so that people know that I figured it out.

0 votes

In addition to what yuminous said, you can also go into settings, and under display -> window, change mode to 2d or viewport, and change aspect to expand.

by (248 points)

This does work, but it doesn't do quite what I need it to.

What isn't working for you? Beyond these solutions, it's possible to change almost anything about control node sizing and the display of content (like text) through scripting.

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 Frequently asked questions and 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 [email protected] with your username.