Search code examples
cocos2d-iphone

Coco2d animation sequence


I have a CCSequence that is executed and just below that in the same function I set three sprites to visible = YES; The issue is that I need them to be visible only after the actions are done.

How can I do this? If I set the alpha in an action and add it to the sequence, will that also remove the touch recognition? I have a gesture Recognizer attached to the cocos2d sprite using a wrapper.

So what is the best way to have this work?


Solution

  • The answer to the first part of your question is to use CCCallFunc, CCCallFuncN, or CCCallFuncND. The animation in one of my apps is done like this:

    CCArray* array = [[CCArray alloc] initWithCapacity:20];
    for (...) {
        [array addObject:[CCMoveTo actionWithDuration:time position:ccp(...)]];
    }
    [array addObject:[CCCallFuncN actionWithTarget:self selector:@selector(animationComplete:)]];
    [sprite runAction:[CCSequence actionsWithArray:[array getNSArray]]];
    [array release];
    

    As for the second part, the alpha affecting touch recognition, I'm not sure. I would think as long as you don't set visible to NO, it would still be touchable.