You can use CCSequence to create an action list. The first action you take should be your regular action (or sequence). The second action should be the CCCallFuncND action, where you can call the cleanup function and pass this sprite.
On top of my head, I would do something like this:
CCSprite* mySpriteToCleanup = [CCSprite spriteWithFile:@"mySprite.png"];
[self addChild:mySpriteToCleanup];
id action1 = [CCIntervalAction actionWithDuration:0];
id cleanupAction = [CCCallFuncND actionWithTarget:self selector:@selector(cleanupSprite:) data:mySpriteToCleanup];
id seq = [CCSequence actions:action1, cleanupAction, nil];
[mySpriteToCleanup runAction:seq];
and in the cleaning function:
- (void) cleanupSprite:(CCSprite*)inSprite
{
[self removeChild:inSprite cleanup:YES];
}
You can add another action between these two actions, as well as to destroy particles for actions, instead of calling it at the end of the function.
source
share