Display objects z index

Hi, I’m making a game and I need to manipulate order of objects on the scene (z index) a lot. The game has top down perspective along with slight angle so that players for example can hide under or stand in front of a tree. I’ve seen methods like toFront or toBack but those are very limited, I’ve also try nasty trick like below but it doesn’t work

group[1], group[2] = group[2], group[1]

Are there any other out of the box ways to manipulate objects’ order?
Cheers :grinning:

Hi, @MattSq,

Try use index parameter in group:insert( [index,] child, [, resetTransform] )

From documentation

index (optional)

Number. Inserts child at index into group, shifting up other elements as necessary. The default value index is n+1 where n is the number of children in the group.

An easy way to move an object above all its siblings (top) is to re-insert it: object.parent:insert( object ) .

If a group has 3 display objects:

  • group[1] is at the bottom of the group.
  • group[2] is in the middle of the group.
  • group[3] is at the top of the group.

Objects at the higher index numbers will be displayed on top of objects with lower index numbers (if the objects overlap).

To get number of childs in group use group.numChildren.

Have a nice day:)
ldurniat

4 Likes

How I missed it, that’s exactly what I was looking for
Thanks and have a nice day too