How can I bring a label to the foreground (in 2d)?

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

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?

:bust_in_silhouette: Reply From: xyzzyx

Now I can answer it myself.
The video 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.

:bust_in_silhouette: Reply From: gonzo191

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.