Вопрос

I am having a little problem animating sprites in Cocos2d-ios v3.0.

I have tried following suggestions from other posts here with similar questions, but I can't get it to work. I am trying to animate a sprite with just 2 .png images, but everything I try gives me an error.

Here is the code I have right now:

//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];

The error message I am getting is:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM insertObject:atIndex:]: object cannot be nil'

If anyone could help me out, I would really appreciate it!

Это было полезно?

Решение

From our discussion in the comments above.

You are adding the png to the batchnode, but you aren't adding the plist to the spriteframecache? This is what I think is missing.

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"run.plist"]
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top