Search code examples
iphoneipadcocos2d-iphonecore-animation

iphone cocos2d CCSequence of Action and CCParticleSystem animation


I´m new to Cocos2d. I´m trying to run two animations one after another. The first one is:

CCAction *walkAction;
CCAnimation *walkAnim = [CCAnimation 
                         animationWithFrames:walkAnimFrames delay:0.15f];
bear = [CCSprite spriteWithSpriteFrameName:@"normal1.png"];        
walkAction =   [CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO];
[bear runAction:walkAction];
[spriteSheet addChild:bear];

The second which I want to fire right after the first one is:

     CCParticleSystem *killPigAnim = [CCParticleSystemPoint particleWithFile:@"killPigAnim.plist"];
     [self addChild:killPigAnim];

How can I achive that when the second one is not an action but the CCParticleSystem object.


Solution

  • You can use the action CCCallFunc to either call the start method on the particle system or call a method in your class which starts the particle system.

    i.e.

    -(void) startParticles
    {
        //Start your particles
    }
    
    
    -(void) myOtherMethod
    {
        ...
        walkAction =   [CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO];
        CCCallFunc *callAction = [CCCallFunc actionWithTarget:self selector:@selector(startParticles)];
        [bear runAction:[CCSequence actionWithActions:walkAction, callAction, nil];
        ...
    }