
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.
// 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 TestAtlas.m file (Example #5) contains a working example of AtlasSprite.
The PerformanceTest example compares Sprite vs AtlasSprite performance (more on this later).
6 comments:
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!
Post a Comment