Which method get called when i remove a node from parent

467 Views Asked by At

I want to know which method of child get called when we remove any Node from its parent.

I created MyLayer by extending Layer class and then add my own sprite MySprite which extend Sprite class of cocos2d-x framework. I need to decrease a counter when child removed so i need a method which i'd override in my MySprite class.

I use this method to remove.

parent->removeChild(child);

Here parent is MyLayer and child is MySprite pointer.

1

There are 1 best solutions below

3
On BEST ANSWER

If the child is running these two methods will be called:

child->onExitTransitionDidStart();
child->onExit();

If you remove the child with cleanup = true(which is the default value), child->cleanup(); will be also called.

So the best solution for you would be to override virtual void onExit(); function of the child. And in the overridden method don't forget to call Node::onExit(); or whatever your superclass will be.