Layering in Cocos creator

In Unity, we have a layering concept according to which we can change the object layer at runtime for 2D games. So I can avoid player 1 moving behind player 2’s object when player 2 is sitting on the sofa.It looks weird. Please, someone suggest some examples for me with some documentation so I can learn. I am using the 2.4.10 version. This feature is available in the above version. Please share that also.

Never used 2.4 but stumbled uppon the z index doc once : Node · Cocos Creator

Isn’t that what you seek ?

In 3.6 you can use the z position for 2d object like for 3d objects if you use a material with the built in sprite shader and with depth enabled.

Thanks for suggesting.

Do you have/know of an example of creating such materials in 3.6? I’m really curious just how much of the z-space I can control with this. Thanks.

Create a new material and set these properties :

  • Effect : builtin-sprite
  • Use alpha test : true
  • Alpha threshold: 0
  • Use Texture : true
  • Depth Test : true
  • Depth write : true
  • IsA2C: true

Every sprite rendered with this material should order themselves using the z position of the node no matter their parenting.
Didn’t test it extansively yet, but seems to work in simple use cases.