Well I was all excited because I managed to jam literally every graphic for a given level into a single texture so now I can just have one SpriteSheet with many atlas sprites as children and reap all the performance benefits thereof...
Or so I thought...
After scratching my head for a few hours and tweaking things, I cannot get the atlas version to perform any better than the non atlas version.
So I made a test project using the Cocos template and just swapped in this code for the HelloWorld's init:
- (id) init
{
self = [super init];
if(self != nil){
BOOL useAtlas = NO;
NSUInteger numSprites = 256;
CCTexture2D *spriteTexture = [[CCTextureCache sharedTextureCache] addImage:@"Default.png"];
CCNode *spriteSheet = [CCSpriteSheet spriteSheetWithTexture:spriteTexture capacity:numSprites];
[self addChild:spriteSheet];
if(!useAtlas){
[self removeChild:spriteSheet cleanup:YES];
spriteSheet = self;
}
CCSprite *aButton;
float mnX = 40.0f;
float anY = 40.0f;
float incX = 10.0f;
float incY = 10.0f;
float anX = mnX;
CGRect texRect = CGRectMake(0.0f, 160.0f, 80.0f, 80.0f);
for(int i=1; i<=numSprites; i++){
if(useAtlas){
aButton = [[(CCSpriteSheet *)spriteSheet createSpriteWithRect:texRect] retain];
}else{
aButton = [[CCSprite alloc] initWithTexture:spriteTexture rect:texRect];
}
aButton.position = ccp(anX, anY);
[spriteSheet addChild:aButton];
[aButton release];
anX += incX;
if(anX >= 280.0f){
anX = mnX;
anY += incY;
}
}
}
return self;
}
And if I toggle the value of useAtlas to YES I get the same FPS. I really think I should be getting 60fps with this number of sprites all being rendered in batch, but both cases render at around 12-15fps on the device. Lowering the number of sprites brings up the frame rate as expected, BUT it changes by the same amount whether using the atlas or just parenting under the layer.
Notes:
- Toggling Compile for Thumb makes no difference
- Toggling compress PNG makes no difference
Please if you see anything striking that I missed, point it out :) I have just recently switched to the new 0.9 api so I may have missed something with the new AtlasSprite -> CCSprite transition.