Axort
Axort

Reputation: 2024

Cocos2d: Change sprite's zOrder dynamically (using CCSpriteBatchNode)

Is there a way to change the zOrder of a sprite rendered by CCSpriteBatchNode? I've tried it like this:

[self reorderChild:mySprite z:indexOfAnArray];

I get this error: 'If CCSprite is being rendered by CCSpriteBatchNode, CCSprite#draw SHOULD NOT be called'

I also tried with the zOrder property of the sprite but unfortunately is read-only. I need to change the zOrder because, depending on the position where my sprite will appear, the zOrder needs to be changed.

Upvotes: 1

Views: 1719

Answers (1)

Saturn
Saturn

Reputation: 18149

self is probably not the parent of sprite. Remember that the parent is the CCSpriteBatchNode that holds it, and self is, from your point of view, probably the scene.

Upvotes: 3

Related Questions