Container Sorting?

I just started using Phaser 3 and I am trying to figure out how to sort a Container with other sprites in a scene.

In Phaser 2, we can use groups to layer objects (which works great); however, group doesn’t work the same way in Phaser 3 and it seems that we need to use setDepth to layer objects as far as I know.

setDepth works great; but, when I add a sprite to a Container, the sprite / this child object’s depth is not working anymore.

Also, there is no way to set Container depth.

I am using Container to recreate an addChild to a sprite.
In Phaser 2, we can easily add a child object to another sprite; but, that is now gone from Phaser 3 :frowning:

For example, I want to create child objects that rotates around a parent object and using Container, it works great but the layering issue.

Anyone know a work around this?
I know I can manually layer the Container object at the correct layer by adding it in the scene manually at the right time. Matrixes / Math translations going to be too much and confusing LOL and I prefer not to go this route.

Also I know Container has sendToBack / bringToTop etc, but that means I have to somehow manually get all sprites on screen? and get their depth to compare with Container’s children’s; so then I can sort them manually by sendToBack / bringToTop etc?

I prefer if we are able to just use setDepth on Container object or perhaps the childrens’ depth work correctly.

Hopefully someone knows a work around to fix this issue, simpler solution which I hope Phaser 3 has.

Thanks.

For the Container’s children, use bringToTop(), sendToBack(), moveDown(), moveTo(), or moveUp(). Don’t use a child’s setDepth() method, it won’t work. If you need to sort all children at once you can use container.list.sort(…).

For the Container itself, setDepth() should work.

4 Likes

Ummm LOL LOL
It works!
I think I have been referring to a wrong site. This site https://rexrainbow.github.io/
Does not list the depth or setDepth as part of the Container class thus I have no idea it has setDepth.

Thanks! Any suggestion what is the best site for me to get all the classes informations?

@farhan for Phaser Docs: https://photonstorm.github.io/phaser3-docs/ =)