-2

In my game, I am running two animations using CCSpawn but it shows only one animation at a time. What is wrong here? 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]]];
LAMBORGHINI
  • 338
  • 2
  • 13
Gaurav
  • 721
  • 5
  • 14
  • both the frame will be try to replace the sprite's texture, so may be you are getting animation for poofAnimate. – Renaissance May 28 '13 at 13:54
  • yes, you got it....now what i do... – Gaurav May 28 '13 at 13:59
  • see i am not sure whether it will work or not but try to make one CCSequence which will have delay and poofAnimate . The dela will be of ((1/20)-(1/22)) and than run that action with CCspawn with runAnimate and (delay and poofAnimate). I am not getting why someone try to animate one single sprite with two different spriteframes object? – Renaissance May 28 '13 at 14:04
  • yes..i did it...but when poof animation run, herobodysprite is not showing run animation. – Gaurav May 28 '13 at 14:07
  • what exactly are you trying to achieve here? You just said you have a problem with your code, There is no console log. What line is the error on? – LAMBORGHINI May 28 '13 at 20:01
  • in last line, in ccspawn, when i put runanimate first then it only show poofanimation, but when i put poofanimate firt then only run animate show....in ccspawn both animation not working at same time – Gaurav May 29 '13 at 07:52

1 Answers1

0

You basically want to display two different frames at the same time on the same sprite. That is just not possible, think about it. What kind of magic do you expect Cocos2d to do for you ? Some animations are just not made to be compatible with each other. It's like if you tried to move a sprite to the left and to the right at the same time, and were surprised it didn't work...

dqms
  • 303
  • 1
  • 10
  • yes...i got it...what u want to say.. but what is functioning of ccspawn – Gaurav May 29 '13 at 07:48
  • CCSpawn allows you to start two or more CCActions at the same time. For example you can use it to move a sprite and rotate it simultaneously. Or to move it and run a CCAnimation on it. But if you try to spawn two CCAnimations on the same sprite it seems quite obvious that you will run into a problem... – dqms May 29 '13 at 12:42