SundayMonday
SundayMonday

Reputation: 19727

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];

Upvotes: 0

Views: 1542

Answers (2)

CodeSmile
CodeSmile

Reputation: 64478

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.

Upvotes: 3

Morion
Morion

Reputation: 10860

First of all, if you look to the code of spriteWithFile: method, you will see that it adds image to the texture cache anyway if cannot find it there.

The second thing you must know, that if you store your art in atlases for reducing memory usage(for example, atlas 2048x2048 pixels with 20 different pictures), spriteWithTexture: will create sprite with whole huge atlas(2048x2048 pixels) texture.

Upvotes: 1

Related Questions