0 votes

Hello guys, im new to godot and im little helpless with my problem here...

So Iv'e made a UI Node which is set to "Full Rect" and added a Label on the Top-Left of the UI as you can see here:

enter image description here

Now I have a Camera-Script that makes my Camera able to drag around.. so since the UI Node is a child of the Camera it gets dragged around as well which is a litte unfortunate

This is the Camera-Script

extends Camera2D

var _previousPosition: Vector2 = Vector2(0, 0)
var _moveCamera: bool = false

func _unhandled_input(event: InputEvent):
        if event is InputEventMouseButton && event.button_index == BUTTON_LEFT:
            if event.is_pressed():
                _previousPosition = event.position
                _moveCamera = true
            else:
                 _moveCamera = false;
        elif event is InputEventMouseMotion && _moveCamera:
            position += (_previousPosition - event.position)
            _previousPosition = event.position

Any ideas how i can fix this problem?

in Engine by (12 points)

Use CanvasLayer node for UI.

1 Answer

+1 vote

Add your Label as a child of CanvasLayer for it to move with the camera.
All UI elements that you need to move with the camera should be a child of CanvasLayer. You can also change the type of your root node to be a CanvasLayer.

by (25 points)
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 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 webmaster@godotengine.org with your username.