Cocos2d v3.0 - 动画精灵



我在 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:]:对象不能为零"

如果有人能帮助我,我将不胜感激!

来自我们在上面评论中的讨论。

您正在将 png 添加到批处理节点,但您没有将 plist 添加到精灵帧缓存中?这就是我认为所缺少的。

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"run.plist"]

最新更新