Roger
Roger

Reputation: 1050

How can I use removeAllChildrenWithCleanup: w/o losing runAction:?

I have an transformation sequence that works fine until I add in removeAllChildrenWithCleanup: at the end of the sequence. What can I do to keep the transformation sequence and run removeAllChildrenWithCleanup: at the end?

Here's a snippet of the code in question:

// Note: spriteSheet is a CCSpriteBatchNode
CCArray *oldSprites = [spriteSheet descendants];
for (int j=0; j < (int)[oldSprites count]; j++) {
    CCSprite *sprite = (CCSprite *)[oldSprites objectAtIndex:j];
    if (sprite != nil) {
        id actionMove = [CCMoveTo actionWithDuration:0.75
                                            position:ccp(0,0)];
        [sprite runAction:actionMove];
    }
}
[spriteSheet removeAllChildrenWithCleanup:YES];

Note: I've tried cleaning up the sprite by using a sequence of CCMoveTo then CCCallFuncND to clean up the sprite, but it doesn't work either. I'm try to use removeAllChildrenWithCleanup:, because I know that removing a child from a CCSpriteBatchNode is very slow.

Upvotes: 0

Views: 596

Answers (1)

anatoliy_v
anatoliy_v

Reputation: 1800

Did you tried CCCallBlock? Something like this:

id actionMove = [CCMoveTo actionWithDuration:0.75 position:ccp(0,0)];
id actionDelay = [CCCallBlock actionWithBlock:^{[sprite removeFromParentAndCleanup:YES]; }];
id sequence = [CCSequence actions:actionMove, actionDelay, nil];
[sprite runAction:sequence];

Upvotes: 1

Related Questions