Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Since your main concern is about memory, I recommend to simply use a texture atlas.</p> <p>I copied your original image into an image editing program to see what its dimensions are. The image is 73x71 pixels in size, that means it's stored in memory as a texture with dimensions 128x128 since textures will have power of two dimensions. This will have the texture use up 64 KB of memory (assuming 32-bit color depth). With a texture atlas you'll be able to pack your textures more tightly, and you can change the frame that is displayed more easily with the <a href="http://www.learn-cocos2d.com/api-ref/latest/cocos2d-iphone/html/interface_c_c_sprite.html#ae41c556a12991defd766670eae6ba700" rel="nofollow">CCSprite setDisplayFrame</a> method.</p> <p>Furthermore, you are using the texture cache:</p> <pre><code>[CCTextureCache sharedTextureCache] addImage:@"player-small.png"] [CCTextureCache sharedTextureCache] addImage:@"player-orig.png"] </code></pre> <p>Unless you explicitly free the memory of that texture, both textures will remain in memory anyway. If you do free the memory of the texture you're not currently using, and exchange these texture often, your game will spend a great deal of time releasing memory and reloading the image from the device's flash memory - even if the image is relatively small. </p> <p>And if there's more than one sprite using either texture it wouldn't make any sense to try and unload/reload the textures because there will be occurrences where two or more sprites will use either texture.</p> <p>Finally, we're talking about 64 KB of memory at most. If you're concerned about memory usage AND performance, the thing you should do is to load PVR textures instead, which are a fraction of the size of a PNG file both in memory and on disk (but losing some color vibrancy).</p> <p>Have a look at <a href="http://www.texturepacker.de" rel="nofollow">TexturePacker</a> for creating texture atlases and PVR images.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload