[Help] Newbie question: Setting up layers with Z Index (SOLVED)

Hello,

I am new to Defold and am slowly picking up game development.

I am experiencing a weird behavior while trying to accomplish something simple:

  1. First, I created a collection with a GO that contains 3 layers of sprites (background). I set the Z index of the sprites accordingly. It appears correctly from the preview screen.
  2. Next, I created a GO that is just a simple bubble.
  3. When I place both these two items in the main.collection, the bubble GO seems to fall between the background layers. I want it to be at the topmost.
  4. So I started fiddling with the Z index (the third position input field… I’m assuming that’s the Z-Index) of the bubbleGO and the background collection on the main.collection. And suddenly the bubble is not appearing anymore – it’s displaying correctly on the preview screen but when built, the bubble is not appearing, and the order background collection seems to shuffle randomly.

The only script I placed in was for the bubble GO to make sure that init was called.

The behavior is consistent as I’ve tried restarting from scratch a couple of time, and the bubble GO always goes missing after playing around with the Z index, and even when i remove the bubble GO and re-add it in, it is still not appearing.

I feel that I’m missing something very fundamental here, would appreciate any help offered here, thanks a lot!

Best regards,
VT

1 Like

First of all, the range of Z values in the default render script goes from -1 to 1. Anything outside these values will not be visible. You can create your own render script and change these values if you wish. Read more about this here.

Second, if you nest game objects within collections their final position, rotation and scale is decided by their own position, rotation and scale in combination with all parent game objects. My guess is that you are forgetting about a parent game objects z position and thus get a world z that goes outside the range in the render script, causing the game object to disappear at runtime. If you are uncertain about the final wold position of a game object you can always print(go.get_world_position())

4 Likes

Thanks! I think I sorted that part out based on your explanations (Phew~~)
Really appreciated it!

1 Like