This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I cant manage to pin Label text and progress bar to camera..
I have smoothing enabled and label is in Camera2D node as a child.
When player runs, camera slowly catches player up, but text is glued to the player, not the camera screen
How can i pin them to what the following camera goes?

in Engine by (227 points)

1 Answer

+1 vote

A Camera2D is not a screen, it's just a node telling its parent Viewport where to look at when drawing nodes (if none it will default to the main viewport).

In 2D, if you want your interface to stay at the same position on screen regardless of the camera's position, a better idea is to put it under a CanvasLayer node.
This way, it will be drawn separately and stay pinned to where you want it to be.

Also the CanvasLayer node doesn't have to be under the camera either, it can be under the root of your scene, as long as your "game camera" is not child of it.

- Root (Node)

    - GameWorld (Node)
        - Avatar (KinematicBody2D)
        - Camera (Camera2D)
        - Map (Tilemap)
        - ...

    - Interface (CanvasLayer)
        - Pause (Button)
        - Health (Label)
        - ...
by (29,510 points)
edited by

Nice explanation! I'd also add you can achieve this with a CanvasLayer instead of a Viewport (not sure of any advantage to using one or the other, but it's what I've used in the past).

Ah yeah, CanvasLayer would be more appropriate indeed, because it's in 2D :)
Edited the answer.

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.