How can I stick text to the screen?

Viewed 202

How can I stick text to the screen?

I have a Player (Node/Node2D/KinematicBody2D) to which Camera2D is attached. And I have Label (Node/Control/Label).

I want the text to always be on the screen, like this.

When a player moves, the label stays on.

1 Answers

Probably the simplest way to do it is to use a CanvasLayer (or multiple CanvasLayer). The gist of it is that the Camera will be limited to its canvas layer, so all you need to do is to put the UI inside a CanvasLayer separate from the world.


A more complex, yet more versatile way to do it is to use a Viewport. The idea is that you will put the game world inside a Viewport, and that Viewport will be inside a ViewportContainer. This will allow you to have a different resolution for the game world and the UI, which might be useful for pixelart games. See How to make a silky smooth camera for pixelart games in Godot.

Related