graphicsopengl-escocos2d-iphonecctexturecache

Appropriate use of CCTextureCache


I'm currently creating a CCSprite like this:

CCSprite *s = [CCSprite spriteWithFile:@"image.png"];

This sprite is the background image of a CCLayer that's used relatively often. Is the following use of CCTextureCache more efficient?

CCTexture2D *t = [[CCTextureCache sharedTextureCache] addImage:@"image.png"];
CCSprite *s = [CCSprite spriteWithTexture:t];

Solution

  • No. Internally, all methods that use an image as a texture (not just CCSprite) will add the texture to the CCTextureCache.

    The only reason why you would want to use addImage directly is when you want to pre-load certain textures so that the first appearance of a node using that texture won't cause a lag during gameplay.