-1

我有一个角色精灵,我必须在它上面运行多个 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 动作可以正常工作。跳跃动作不起作用。我所做的?请帮我

4

2 回答 2

0

Assertion failure in -[CCSprite setTexture:]. 就这样?我相信你的错误信息有点长。您还可以查看 cocos2d 源代码,因为它是开源的,并查看导致此断言失败的行。

无论如何,您的麻烦似乎只是尝试在单个精灵上使用来自不同精灵表的帧的结果。将您的动画放置到单个精灵表中,它应该可以正常工作。

于 2013-10-23T10:34:17.227 回答
0

您必须停止 walkSlow 动作,[_charactar stopAllActions]因为 walkSlow 无休止地运行。

于 2013-10-22T20:49:19.767 回答