"2D" Layers

I’m just getting started using Panda to develop a 2d space game using the asteroids tutorial for a basis.

I’ve added a new “sprite” but am having trouble with the layer the new sprite is displayed at. From what I see in the code, its really 3d with 2d sprites being placed at different y depths to make layers. The stars are at y=200 and sprites are at y=55. I’ve tried placing my new sprite at 50 and 60 but in all cases, the new sprite is rendered on top of the ship but underneath the asteroids.

What am I missing to control what layer a sprite is rendered at?

If you are parenting things to render2d or aspect2d, the depth test is disabled by default. You can renable it with:


Or, you can use scene graph order instead of the y coordinate to determine overdraw. This is the default behavior of render2d. With scene graph order, children are drawn on top of their parent nodes, and sibling nodes are drawn in order from left to right, where rightmost nodes are on top. You can use child.reparentTo(parent, sort = xx) to control the relative ordering of sibling nodes. You can also use explicit binning with node.setBin(‘fixed’, xx) if the standard ordering techniques are insufficient.


Thanks much!