سؤال

I have a CCLayer which has multiple children (Sprites, CCMenuItemImages ets). And these children are having their children (mostly CCLabel*** or CCMenuItemImages). So I want to fade out the all the grand-children and children of the layer and then once all are faded I want to remove the CCLayer.

I am able to apply fade action to the hierarchy. But if I do [CCLayer removeFromParentWithCleanup:YES], then it removes immediately while still some children are running with fade action.

So my question is how can i remove the parent layer once all the gran-children and children are faded (opacity = 0).

Edit: Here is a code snippet

for(CCNode *node in itemLayer.children)
{
    for(CCSprite *sprite in parentLayer.children)
    {
        for(id item in sprite.children)
            [item runAction:[CCFadeTo actionWithDuration:2.5f opacity:0]];
        [sprite runAction:[CCFadeTo actionWithDuration:2.5f opacity:0]];
    }
}

itemLayer is the Parent CCLayer which has a CCNode *node. node is having children and each children have their children. So I want to remove the node and its parent itemLayer once all the actions completes on children and gran-children. How to do this?

هل كانت مفيدة؟

المحلول

Make your top level container a CCNodeRGBA and set in the init :

self.cascadeColorEnabled=YES;
self.cascadeOpacityEnabled=YES;
self.opacity=255;

When you run a CCFadeAction on that, the node will do all the forklifting of cascading down to children and grand-children. At the end of the fade action,

id fade = [CCFadeTo actionWithDuration:2.5 opacity:0];
id done = [CCCallBlock actionWithBlock:^{
    [self removeFromParentAndCleanup:YES];
    // plus whatever else you see fit
}];
id seq  = [CCSequence actions:fade, done, nil];
[self runAction:seq];

ob cit : from memory, not compiled nor tested, YMMV

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top