Pin the Label text and such

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Serenade
:warning: Old Version Published before Godot 3 was released.

Hey!
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?

:bust_in_silhouette: Reply From: Zylann

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)
		- ...

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).

jackmakesthings | 2017-04-01 21:41

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

Zylann | 2017-04-01 22:22