从sprite表动画精灵动画崩溃

时间:2013-05-03 07:47:17

标签: iphone ios6 cocos2d-iphone

以下是我正在使用的代码

-(Void)addSprites{
     [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"image.plist"];

    CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"image.png"];
    [self addChild:spriteSheet];

   // Load up the frames of our animation
    NSMutableArray *walkAnimFrames = [NSMutableArray array];
    for(int i = 1; i < 5; i++) {
        [walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"image%d.png", i]]];
    }
   // CCAnimation *walkAnim = [CCAnimation animationWithFrames:walkAnimFrames delay:0.1f];
    CCAnimation *walkAnim = [CCAnimation animationWithSpriteFrames:walkAnimFrames delay:0.20f];
    // Create a sprite for our bear

    background = [CCSprite spriteWithSpriteFrameName:@"image1.png"];
    background.position = ccp(280, 175);
    self.walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim]];
   //[_bear runAction:_walkAction];
    [spriteSheet addChild:background];  
}
 -(void)startAnimation{
     [background runAction:walkAction];
}

但是app崩溃了

  [background runAction:walkAction];

错误消息是  CCSpriteFrameCache:尝试使用文件'fisherman.png'作为纹理 2013-05-03 13:30:44.085 * 断言失败 - [CCSprite runAction:]由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'参数必须为非零'。我通过调用动作

来尝试它
 [background runAction:walkAction];

in - (void)addSprites {......}方法但仍然会发生同样错误的崩溃。

有人可以帮我解决这个问题吗?

0 个答案:

没有答案