Reputation: 38213
If I have several identical sprites on the screen at once, do I need to load one image for each of the sprite, or can I simply re-use the images somehow?
i.e,
Do I need to do this?
CCSprite *mySprite1 = [CCSprite spriteWithFile:@"mySprite.png"];
CCSprite *mySprite2 = [CCSprite spriteWithFile:@"mySprite.png"];
Or is there a better way to deal with identical sprites?
Upvotes: 2
Views: 390
Reputation: 418
Your solution is fine. The first call to spriteWithFile: will load the texture and add it to the shared CCTextureCache. The second one will check to see if the texture already exists, and this time will reuse it from the first one.
Upvotes: 5