Search code examples
cocos2d-iphonecocos2d-xmemory-management

cocos2d onEnter, onExit


eg)
1. When X sprite is touched, pointer of X is stored in class Y
2. when X sprite is removedFromParent, X sprite will notify Y that it's going away

How do I achieve the second step?
Specifically, onExit(of class X) is a good place to do this kind of stuff?
When does onEnter/onExit get called? I don't find the reference helpful on this.

  • (void) onExit callback that is called every time the CCNode leaves the 'stage'. If the CCNode leaves the 'stage' with a transition, this callback is called when the transition finishes. During onExit you can't access a sibling node.
X::onExit()
{
getY()->notify_X_Dies(this);
}

Solution

  • yeah, you are right. onExit is called when you remove node from it's parent, or when it's parent is removed from the stage/other parent.