我在Cocos2d-ios v3.0中为精灵制作动画有点问题。
我已经尝试过以下其他帖子提出类似问题的建议,但我无法让它发挥作用。我试图用2个.png图像动画一个精灵,但我尝试的一切都给了我一个错误。
以下是我现在的代码:
//adding the png with all the sprites
CCSpriteBatchNode *runSheet = [CCSpriteBatchNode batchNodeWithFile:@"run.png"];
[self addChild:runSheet];
//The sprite animation
NSMutableArray *runAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 2; ++i)
{
[runAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat:@"run%d-HD.png", i]]];
}
CCAnimation *runAnim = [CCAnimation
animationWithSpriteFrames:runAnimFrames delay:0.1f]; //Speed in which the frames will go at
//Adding png to sprite
fufunakan = [CCSprite spriteWithImageNamed:@"run1-HD.png"];
//Positioning the sprite
fufunakan.position = ccp(self.contentSize.width/8,self.contentSize.height/5);
//Repeating the sprite animation
CCActionAnimate *animationAction = [CCActionAnimate actionWithAnimation:runAnim];
CCActionRepeatForever *repeatingAnimation = [CCActionRepeatForever actionWithAction:animationAction];
//Animation continuously repeating
[fufunakan runAction:repeatingAnimation];
//Adding the Sprite to the Scene
[self addChild:fufunakan];
我收到的错误消息是:
*由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:'* - [__ NSArrayM insertObject:atIndex:]:object不能为nil'
如果有人能帮助我,我会非常感激!
答案 0 :(得分:1)
我们在上述评论中的讨论。
您正在将png添加到batchnode,但是您没有将plist添加到spriteframecache中?这是我认为缺少的。
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"run.plist"]