0
votes

I have a CCSpriteSheet and a CCSpriteBatchNode animating from a .png and .plist files running perfectly, but, is there any way to know in which frame is the anymation in order to launch another CCAction??

For example, I have a CCAnimation with 30 frames and I want animate another sprite when the animation is in frame 15. Is this possible??

Thanks in advance.

2
Dunno that. But in your example, you could do it by scheduling a method. Basically, if your animation has a delay of 0.05 per frame, then you should schedule a method to trigger after (0.05 * 15). Such method executes the other animation. - Voldemort

2 Answers

2
votes

Split the animation up into parts and use a CCSequence. For example:

CCAction *Action = [CCSequence actions:
                        [CCAnimate actionWithAnimation:myCCanimationPart1],
                        [CCCallBlock actionWithBlock:^
                         {
                            [myOtherSprite runAction:(otherAnimationAction)];
                         }],
                        [CCAnimate actionWithAnimation:myCCanimationPart2],
                        nil];
0
votes

I typically fulfill this kind of need with something like this code fragment from one of my games :

float stall;
CCAnimation *secondAnim;
CCSprite *secondSprite;
NSString *dyingFx;
id sound = (self.alive ? [GENoopAction action] : 
                         [GEPlayFx actionWithSoundFile:dyingFx]
            );

id second = [CCSequence actions:
        [CCDelayTime actionWithDuration:stall]
        , [CCShow action]
        , sound
        , [CCAnimate actionWithAnimation:secondAnim]
        , [CCCallFunc actionWithTarget:self selector:@selector(hurtComplete)]
];
secondSprite.visible= NO;
[secondSprite runAction:second];

GEPlayFx and GENoopAction are toys i created for myself (CCActionInstant implementations).