Reputation: 12367
In Cocos2d v0.99 there's a class named CCSpriteFrameCache. I can load all the sprite frames
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"images.plist"];
and then I can use those loaded frames
CCSprite *sprite=[CCSprite spriteWithSpriteFrameName:@"img01.png"];
Now my question is: Do we create a big sprite sheet that will hold every single image that we're going to use for animations? I mean, I thought I'd have several sprite sheets for different animation objects. If this question is answered NO,so that I load each sprite differently, then my second question is how do I refer to a frame in a specific sprite sheet?
Upvotes: 1
Views: 908
Reputation: 64478
If possible, cram as much images into as few texture atlases as possible. The determining factor is quite often z ordering. If you have two atlases and two sprite batch nodes, then each sprite batch node can only render their sprites on their z order, while the sprites in the other batch node are either always in front or behind.
You do not need to know which texture atlas (sprite sheet) a sprite frame came from. Just reference it by name. If you need to know which texture the frame refers to, check the sprite frame's texture property and compare it with the texture property of the sprite batch node.
Upvotes: 3
Reputation: 69027
Now my question is: Do we create a big sprite sheet that will hold every single image that we're going to use for animations?
yes, or you can have multiple sprite sheets if you have many different frame images...
I mean, I thought I'd have several sprite sheets for different animation objects.
It depends on the size of the resulting sprite sheet. In principle it is convenient to organize the different frames of the same animation within the same sheet, but if your frames occupy, e.g., 600x600, your sprite sheet will occupy the same memory as a 1024x1024 sheet, so you are better off adding some more frames to that same sheet, even if it belogs to a different animation. In general, you can play with the sheet size, as long as both dimensions are a power of 2, you will not have inefficiencies as to memory occupation and you can organize your frames into different sheets if that makes sense to you.
If this question is answered NO,so that I load each sprite differently, then my second question is how do I refer to a frame in a specific sprite sheet?
by the original filename that was composed into the sprite sheet...
hope it helps...
Upvotes: 4