Search code examples
cocos2d-iphonelayerchildreninsertion

Cocos2d insert sprite (child of layer) between other children without z management


Imagine a pack of cards seen from above (this is a metaphor, not the real thing). What I do currently is adding cards on top of another to my layer using addChild. This is one of the rules of drawing order in Cocos2d:

Where nodes have the same parent and same zOrder: nodes are drawn in the order they were added as child

What I want to do is to replace a card with another, without changing its drawing order, and without using the z property (basically, I want to insert children between others).

How do I do?


Solution

  • There's no way. You will need to use z-order. Is the only way to cocos2d know the order of drawings.

    But, Why the reason to don't use z-order? It's purpose is only and exactly to define drawing order. If you are using it to identify your sprites, use tag property instead.