Tuesday, 28 May 2013

How to run two animation at same time at same sprite?

How to run two animation at same time at same sprite?

In my game i am running two animation by ccspawn but it shows only one animation at a time. what i do? here is my code.....
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"walkcycle.plist"] ;
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"walkcycle.png"];
[heroWorldLayer addChild:spriteSheet];

NSMutableArray *runFrames = [NSMutableArray array];
for(int i = 1; i <= 11; ++i) {
    CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache]    spriteFrameByName:[NSString stringWithFormat:@"Run_Anim00%02d.png", i]];
    [runFrames addObject:frame];
}
id runAnim = [CCAnimation animationWithFrames:runFrames delay:1.0/22.0];
id runAnimate = [CCAnimate actionWithAnimation:runAnim restoreOriginalFrame:NO];
//    _runAction = [CCRepeatForever actionWithAction:runAnimate];
//    [heroBodySprite runAction:_runAction];

NSMutableArray *poofFrames = [NSMutableArray array];
for(int i = 1; i <= 10; ++i) {
   CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"Poof00%02d.png", i]];
   [poofFrames addObject:frame];
}
id poofAnim = [CCAnimation animationWithFrames:poofFrames delay:1.0/20.0];
id poofAnimate = [CCAnimate actionWithAnimation:poofAnim restoreOriginalFrame:NO];
//    id poofAction = [CCRepeatForever actionWithAction:poofAnimate];
//    [heroBodySprite runAction:poofAction];

[heroBodySprite runAction:[CCRepeatForever actionWithAction:[CCSpawn actions:runAnimate, poofAnimate, nil]]];

No comments:

Post a Comment