How do I fit a GUI properly within a camera?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jobax

Hi I have a player sprite you can move around with a camera as a child of this sprite, so the camera moves with it. What would be the best way of fitting a GUI (labels, text boxes, etc) into this zoomed view? I don’t really care about the GUI moving along with the camera as it only appears when you are stationary.

E.g. I have a colorrect node as a child of the camera which represents a text box, but I have to move it manually in the 2D space and it’s not aligned perfectly. The draw screen limits of the camera isn’t accurate e.g. I place the rect inside the camera “box” at the bottom in the 2D workspace but if I run the game, the rect will be more in the middle of the screen.

How do I properly do this within the camera view itself? Thanks.

Try looking for containers in the Godot docs, they might be what you need.

DodoIta | 2018-03-19 10:22

Thanks I tried that but the containers just don’t adjust properly while being a child of the camera node. If I put a camera in a container, the game just crashes.

jobax | 2018-03-19 22:30

:bust_in_silhouette: Reply From: coffeeDragon

I would suggest not putting any UI elements as the child of the camera.
Use a canvasLayer instead and just put your UI elements in there, that’s desinged for UI elements which don’t move in corralation to the camera. See:

Or if you want it bound to the player Sprite, just add it there and play with it’s positioning till you get it right.