cocos2d v0.7.1 supports SpriteSheets. An SpriteSheet basically is an image that contains subimages, and these subimages can be used as sprites. In cocos2d v0.7.1 these new sprites are called AtlasSprite.
These are the benefits of using AtlasSprite instead of the normal Sprite:
- Reduces texture memory since all the sprites are in one big image.
- Reduces render time since there are less OpenGL calls. The new order is O(1) while the order of using normal Sprites is O(n). If you have 400 AtlasSprites, now you have to do 6 OpenGL calls. With 400 Sprites you have to do 400 *6 OpenGL calls.
How do you use it?:
// Create the AtlasSpriteManager // You can use a .PNG file or a PVRTC image. // capacity is an optional parameter. It is just a hint that means the quantity of total sprites. // You can add more (or less) sprites than the quantity. // grossini_dance_atlas.png is an image than contains the subsprites. AtlasSpriteManager *mgr = [AtlasSpriteManager spriteManagerWithFile:@"grossini_dance_atlas.png" capacity:50]; // You create the sprite AtlasSprite *sprite = [AtlasSprite spriteWithRect:CGRectMake(x,y,85,121) spriteManager:mgr]; // you add the sprite to the parent // the parent must be the AtlasSpriteManager // z must be 0. // You can add tags if you want. [mgr addChild:sprite z:0 tag:kTagSprite1]; // you can transform the sprite sprite.position = cpv( 200,300 ); sprite.rotation = 90; sprite.scale = 2.0f; // you can run actions in this new sprite [sprite runAction: [RotateBy actionWithDuration:2 angle:360]];
The AtlasSpriteTest.m file contains a working example of AtlasSprite.
The PerformanceSpriteTest example compares Sprite vs AtlasSprite performance (more on this later).
[edit: updated links]





Hi & thanks for your job !!!
How could i get the version 0.7.1? on the svn repository?
yes, v0.7.1 is not ready yet. But you can get the SpriteSheet implementation from the SVN repository
Nice work!
Thanks again for all your hard work.
Is there an easy way to use the spriteSheets for animation?
What tools are used to create sprite sheets?
Yes, animations are supported too.
Use the latest version from the SVN.
See the AtlasDemo example
Thanks a lot! This is very usefull!
I tried downloading the file, but i get a web error. does anyone know where i can get AtlasDemo Example.
@rzimmerman: i’ve just updated the links.
Thanks. Is there any reason you have to explicitly call addAnimation on the sprite to add the animation to the sprite’s dictionary? Rather, why isn’t it done automatically?
I was using setDisplayFrame and it kept crashing till I realized the animation dictionary was empty.
how can we create spritesheet? I tried many tools but get no succes.