Game Development Reference
In-Depth Information
NSMutableArray* frames = [NSMutableArray arrayWithCapacity:frameCount];
for (int i = 0; i < frameCount; i++)
{
NSString* file = [NSString stringWithFormat:@"%@%i.png", frame, i];
CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
CCSpriteFrame* frame = [frameCache spriteFrameByName:file];
[frames addObject:frame];
}
// Return an animation object from all the sprite animation frames
return [CCAnimation animationWithSpriteFrames:frames delay:delay];
}
The big plus is now, once again, that you can create an animation from a texture atlas
using sprite frame names with just one line of code:
// Create an animation object from all the sprite animation frames
CCAnimation* anim = [CCAnimation animationWithFrame:@"ship-anim"
frameCount:5
delay:0.08f];
The much, much bigger plus, though, is that you can now work with your animations
as single files and only later create a texture atlas. All you have to do is to change one
line of code from using animationWithFile to the animationWithFrame
method. This allows you to quickly prototype animations using individual files, and
only when you're satisfied do you pack the animation frames into a texture atlas and
load the animation images from it.
You'll also find this updated CCAnimationHelper code in the Sprites02 project.
All into One and One for All
Whenever possible, you should add all your game's images into one texture atlas or as
few as possible, and preferably use one CCSpriteBatchNode to draw all the sprites
from the same texture atlas. It's more effective both from a workflow perspective and
for performance to use one texture atlas with dimensions of 2048×2048 than 10 smaller
ones, and you will have to use at least 10 sprite batch nodes instead of just one. That
Search Nedrilad ::




Custom Search