I'm trying to animate a CCSprite in cocos2d v3 following this question, but I'm getting the following error message in Log:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM
insertObject:atIndex:]: object cannot be nil'
This is my code:
NSMutableArray *animationFrames = [NSMutableArray array];
int frameCount = 0;
for(int i = 1; i <= 9; ++i)
{
CCSpriteFrame *spriteFrame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat:@"hero-%d.png", i]];
[animationFrames addObject:spriteFrame]; //ERROR OCCUR THIS LINE
frameCount++;
if (frameCount == 8) break;
}
The problem is that all spriteFrames are nil, but I don't why. I already tested the i values with NSLog, and also tried to add hero-1.png to a CCSprite object and works fine. I also tried to add all fixed hero-1.png in all frames to verify if the problem was with i variable. But didn't work also.