I have a class representing my character in Cocos2d.
I've exported the spritesheet + .plist file.
The character has multiple animations.
The frames are simply called "Character_1.png".
Up to four. This is the basic walking animation.
In many sprite animation tutorials I found this sample code, which loops though the sprite frame cache and just adds it to an array so you can animate it:
for(int i = 1; i <= 4; ++i) {
[animationFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"Character_%d.png", i]]];
}
However, because most of my sprites will be animated just like this, I'd like to delegate this to an super class.
I thought about calling it something like
spriteWithAnimations:(NSArray *)animationNames
and then I'd look though them, just like in the example above.
So as a parameter in the array I'd get a string @"Character_%d"
, I'd make a while loop and check if the file exists, and while so, I'd add it to the array.
The only problem is, that I cannot check if a frame "Character_05.png" exists, because CCSpriteFrameCache
has no such method.
How is this usually solved?