我有一个角色精灵,我必须在它上面运行多个 ccAnimation,比如运行动画和跳跃动画。为此,我创建了 spritesheet 并为其分配了框架。这是我的代码:
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"ch_run_slow.plist"];
spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"ch_run_slow.png"];
[self addChild:spriteSheet];
_character = [CCSprite spriteWithSpriteFrameName:@"Ch_run_slow_12.png"];
_character.tag=1;
[spriteSheet addChild:_character];
我的动画功能是:
-(void) characterSlowRun
{
NSMutableArray *runSlowAnimFrames = [NSMutableArray array];
for (int i=1; i<=12; i++)
{
[runSlowAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"Ch_run_slow_%d.png",i]]];
}
CCAnimation *runSlow = [CCAnimation
animationWithSpriteFrames:runSlowAnimFrames delay:0.1f];
runSlowAction=[CCAnimate actionWithAnimation:runSlow];
runSlowAction = [CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:runSlow]];
[_character runAction:runSlowAction];
}
而Jump Action方法是:
-(void) characterJumpSmall
{
[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFramesFromFile:@"ch_run_slow.plist"];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"ch_jump_small.plist"];
spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"ch_jump_small.png"];
NSMutableArray *jumpSmallAnimFrames = [NSMutableArray array];
for (int i=1; i<=13; i++)
{
[jumpSmallAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"Ch_jump_small_%d.png",i]]];
}
CCAnimation *jumpSmall = [CCAnimation
animationWithSpriteFrames:jumpSmallAnimFrames delay:0.1f];
jumpSmallAction=[CCAnimate actionWithAnimation:jumpSmall];
[_character runAction:jumpSmallAction];
}
在初始化时我调用 [self characterSlowRun]; 在 ccTouchesEnded 我使用 [_character stopAction:runSlowAction]; [self characterJumpSmall]; 当点击屏幕崩溃时,最初 runSlow 动作可以正常工作。跳跃动作不起作用。我所做的?请帮我