0 votes

I'm trying to keep some Control nodes in the corners of the window, yet when I resize it, they don't move and get cropped out of view (or alternatively don't expand outwards to match a larger window size).
Here's my tree:
scene tree

I've tried adding this to the Camera2D's script within _process():
get_viewport().size = OS.get_window_size()

I've also tried setting the UI rect_size to equal the Camera2D's get_viewport().get_visible_rect().size, and doing the same procedure (but targeting the UI node, not the Camera2D) for the Velocity Display and Cursor Info nodes.

The anchor values on the labels are actually a little strange, to be honest. I've got them set for -.4 on the Y-axis and .4 on the X-axis. In my head that means they should be located at -.4 * (screen_height) on the Y-axis relative to the Velocity Display react. Yet they correctly display inside the window (as long as I haven't resized it from the project setting).

Here's an image of the app at the project default of 1920x1080:
default res

And one where I've resized it in the vertical axis slightly. Note that the CursorPos and X-Velocity labels are no longer visible. Resizing horizontally does something similar.
modified res

If anyone knows what I might be missing, I'd appreciate some guidance.
An up-to-date (as of this post) version of my project is located here:

in Engine by (747 points)

are you using "Layout->Full Rect" on the control nodes?
enter image description here

try putting root control node outside of the camera2d node, as the position of the camera2d node may be affecting the positioning of the control node (just a blind guess)

1 Answer

+2 votes
Best answer

Your gui should not be child of your camera. It should be child of a CanvasLayer for example.

by (3,505 points)
selected by

Precisely the answer, I read it somewhere else and hadn't gotten around to resolving this Q. Thanks

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.