如何在同一个精灵上同时运行两个动画?

时间:2013-05-28 13:47:27

标签: cocos2d-iphone box2d-iphone

在我的游戏中,我使用CCSpawn运行两个动画,但它一次只显示一个动画。这有什么不对?这是我的代码。

[[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]]];

1 个答案:

答案 0 :(得分:0)

你基本上想要在同一个精灵上同时显示两个不同的帧。这是不可能的,想一想。您期望Cocos2d为您做什么样的魔术?有些动画并不是为了彼此兼容。就像你试图同时向左和向右移动一个精灵一样,并且惊讶它没有用......