+2 votes

Hi guys,
How to change order (or succession - google translator - I dont no how to say it) of object in scene - if I want to have text in the foreground and other objects in backround.

in Engine by (61 points)

1 Answer

+2 votes

The answer to this depends on exactly what you are doing.

Generally the nodes are drawn in order, that means the first child is drawn first, then the second one etc.

For isometric games there is also the Y ordering where children of the tilemap are drawn depending on their Y-value on the screen. Objects that are closer to the bottom of the screen are considered in front of objects further up.

Then there is a Z-value for all objects that inherit Node2D that you can use to move some objects to another layer so to speak.

Depending on what exactly you want to achieve you should choose one of these three methods.

Edit: dc1a0 reminded me of CanvasLayers. They have a property that is just called "layer" which kind of works like a Z-value. But additionally they can be made independent of the camera (good for a HUD) or to move faster than other layers (ParallaxBackground). More infor here.

by (372 points)
edited by

With the specifics of their question, I'd also add that there's CanvasLayer that puts all its children in the front, and ParallaxBackground that puts all its children in the back.

With CanvasLayers I always think of camera independent movement and OPs questions (to me) didn't sound like he wants to do a HUD, but I might be wrong. I added the info to my answer anyways, thanks! :)

I want to say - in 2d from top down view - can i do it from inspector?

You have to give some more information on what you want to achieve. Do you want to do a HUD? Then use CanvasLayer. Do you want to do name tags/health bars? Use the Node2D Z-value. You can do all of these things from the editor without any coding.

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 Frequently asked questions and 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 [email protected] with your username.