0 votes

I have a background that is made as a sprite with a texture.
When I want to place a label now on top of the background I can only see the text of label when I move it outside of the background but not on the background.
The label seems to be behind the background.
But the label class does not have a value or a function to set the z position.

My solution was to set the z value of the background sprite to -1 then the label is in the foreground.
Are there also other solutions?

in Engine by (72 points)

2 Answers

+1 vote

Now I can answer it myself.
The video https://www.youtube.com/watch?v=MUqWgOBN2MU&index=15&list=PLS9MbmO_ssyAXRl-_ktrebQBFxjSQt7UX is very helpful.
I did not see that before.
You need to place your label on a CanvasLayer (and optionally set the Layer attribute).
Or you place your background on a ParallaxBackground together with a ParallaxLayer.

by (72 points)
+2 votes

I know you've already answered this yourself, but for me the better solution was to create a Node2D element and child the UI elements to it. I did this because the Node2D has a z property and it can be hidden or shown at my discretion which the CanvasLayer didn't. Useful when you want to show menu panels i.e. pause menu.

The problems I found with the CanvasLayer is that it can't be hidden and if you display a panel over it, all of its children elements disregard your sort order and still show over eveything.

by (122 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.