Game Development Reference
In-Depth Information
[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
[[CCTextureCache sharedTextureCache] removeUnusedTextures];
Obviously you should call these methods only when you want to remove unused tex-
tures. You typically do that after changing scenes—not during game play. Keep in mind
that changing scenes causes the previous scene to be deallocated only after the new
scene has been initialized. This means you can't use the removeUnused methods in
the init method of a scene because the textures will still be in use—that is, unless
you use the LoadingScene from Chapter 5 in between two scenes, in which case
you should extend it so that it removes unused textures before replacing itself with the
new scene.
If you absolutely want to remove all textures from memory before loading new ones,
you should use the purge methods instead:
[CCSpriteFrameCache purgeSharedSpriteFrameCache];
[CCTextureCache purgeSharedTextureCache];
In this chapter, you learned how to use a CCSpriteBatchNode to render multiple
sprites using the same texture faster, whether that texture is a single image or a sprite
frame of a texture atlas.
Subclassing your game objects from CCSprite also introduces a few subtle differen-
ces and stumbling blocks, which I demonstrated earlier in this chapter, before moving
on to show you how to create sprite animations. Because the code to create animations
is very complex, I gave you the solution in the form of a CCAnimationHelper cat-
I also showed you how to work with texture atlases and why and how you should use
them. Of course, one can't say “texture atlas” without mentioning TexturePacker in the
same sentence. It's hands down the best tool to create and modify texture atlases, and if
you don't want to spend money on it, you can still use the free command-line version
without the advanced features.
Search Nedrilad ::

Custom Search