Replies: 4 comments 3 replies
-
I agree By default everything you add to the Scene Tree is on CanvasLayer 0 and z_index 0, has no Ysort so everything is 2D sorted using the scene tree hierarchy. Remember: With CanvasLayer nodes you can override this default and separate your scene tree into bigger sorting layers/groups. Within these CanvasLayers you can still do all the z_index and Ysort and tree hierarchy sorting you want. |
Beta Was this translation helpful? Give feedback.
-
Apart of what was mentioned before, Control nodes are not meant to work as Node2D, these are made to be arranged with layers, containers, anchors, et cetera, adding Node2D properties can make these a lot more complex to use. |
Beta Was this translation helpful? Give feedback.
-
Real world example where I needed z-index: Inventory slots. I had them as controls in a ...BoxContainer, and this resulted in lower line's slots (and their menus) overlaying upper ones. |
Beta Was this translation helpful? Give feedback.
-
Z-Index for Control nodes was implemented in godotengine/godot#68070. I believe, that this can be set as resolved. |
Beta Was this translation helpful? Give feedback.
-
I know that this was discussed before, Control nodes will respect the order that they are created on the scene, which is ok.
But if for some reason the user need a control node inside a Node2D, it will start using the zindex of the parent like this:
(by the order the blue box should stay behind)
Yes, you can instantiate it as child of a Node2D, but this not always is possible as you can't anchor inside a Node2d. Alternatively can instantiate it as a child of a Canvas Layer, but I didn't tested it, and to be honest, is just complicating something simple.
Ok, a real world example:
I created a Pause Screen, which is a control node as root, a color rect which fill all the screen and some labels centered. The game is a tile matching game, which when a block(sprite2d) switches the position with another block it do a small animation, it increase the scale of the left block, and reduce of the right. The problem is to this effect work I need to increase the z-index of the left block during the movement, so if the Pause screen is called the block will stop the animation and it will be ahead of the color rect because of the zindex.
My workaround was to set the animation player pause mode, so the animation completes and make it less noticeable. I can't make the pause screen as a child of a Node2D because of the anchor, I still need to try the canvas layer.
If the Z-index was available, it will be a LOT easier.
Beta Was this translation helpful? Give feedback.
All reactions