如何使用removeAllChildrenWithCleanup:没有丢失runAction:?

时间:2012-10-18 18:19:18

标签: cocos2d-iphone

我有一个转换序列可以正常工作,直到我在序列结束时添加了removeAllChildrenWithCleanup:我该怎么做才能保持转换序列并在最后运行removeAllChildrenWithCleanup?

以下是相关代码的片段:

// 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];

注意:我已经尝试使用一系列CCMoveTo清理精灵,然后使用CCCallFuncND来清理精灵,但它也不起作用。我尝试使用removeAllChildrenWithCleanup :,因为我知道从CCSpriteBatchNode中删除一个孩子非常慢。

1 个答案:

答案 0 :(得分:1)

你尝试过CCCallBlock吗?像这样:

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];