Local Z Order not working

Hey guys I’m making a “don’t touch the white tile sort of game”. I’m having an issue dealing with local z order of dynamically added sprites to a layer I define in a csd file.


I’ve tried so many different variations of sorting the z order but nothing seems to affect the layout. I event tried ui::Helper::doLayout(rootNode “and poleContainer”)

The pole objects extend Sprite

here’s the reordering the z part.

Like i said I’ve tried nearly everything. If anyone has dealt with this issue (and I’m sure some of you have) I’d love some help. Thanks.

What object type is polecontainer?

poleContainer is a cocos2d::Node

@zanemx I need to your whole function for adding poles to the container. So I can see how you’re adding them.

Also have you tried this. I believe the reorderChild function may not be working as you expect. To confirm Z order is working correctly. As a test try setting an int counter for zOrder and pass it in every time you add a pole.

int zOrderCount = 0;

..

poleContainer->addChild(p, zOrderCount);
zOrderCount++; 

That should create a new pole in front of all the ones that came behind it, every time.

Edit: Actually I think the fix may be just to make sure you pass in a z value when you add the child before you re-order the child. Just send me that code first with a better explanation of how you want the poles to appear.

Thanks UIDeveloper99.

This piece of code sorts the poles properly in relation to each other. But not in relation to menus and other ui elements.

for some reason all calls to set local z order of the poles is not working. I also tried what you suggested and tried setting the z order before being parented.

The higher poles should display behind the lower ones. Which they do using setGlobalZOrder but not setLocalZOrder. Very frustrating.

If I were you I would set the Z order when you add the child. That would ensure that you’re setting the Z order for the right coordinate system local or world.

This may be a stupid question but you have added all the containers and menus etc as children to the main scene/layer?

When you add the containers I would set all their Z orders when I add them. e.g.

layer->addChild(menu, 10); // Draw on top
layer->addChild(poleContainer, 9); // Second
layer->addChild(fogContainer, 8); // 3rd

Or whatever order you have them. The highest comes first.

Try using addChild(child, z) value like I said in the previous post for adding poles. When you add them as a child to the parent container like that with the Z value as a parameter. The z order should be the local Z order to the container.

See how you get on with that.