Suppose I need several CCSprite
s using the same image. I can think of the 2 following solutions:
The image is in a separate file "bg.png"
CCSprite *image1 = [CCSprite spriteWithFile:@"bg.png"];
CCSprite *image2 = [CCSprite spriteWithFile:@"bg.png"];
The image is in a spritesheet "bg_sheet.png"
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"bg_sheet.png"];
Then
CCSprite *image1 = [CCSprite spriteWithSpriteFrameName:@"bg.png"];
CCSprite *image2 = [CCSprite spriteWithSpriteFrameName:@"bg.png"];
My questions are:
You are not right. In both cases image will be placed into the memory only once. You can check spriteWithFile:
code. It tries to find sprite frame in the sprite frame cache and load it only if there is no needed frame was found.
Using spritesheets help to save memory. For example, for image with size 129x129 will be created texture with size 256x256. But you can add many of such images in one spritesheet and only one big texture will be created( i mean, it there will be spritesheet 1024x1024 or 2048x2048 there will be only one texture with the same size).