Game Development Reference
In this chapter, I focus on working with sprites. You can create sprites in numerous ways
from individual image files and texture atlases. I also explain how to create and play
A texture atlas is a regular texture that contains more than one image. Often it's used to
store all animation frames of a single character in one texture, but it's not limited to
that—in fact, you can place any image into a texture atlas. The goal is to get as many
images as possible into each texture atlas. To help create a texture atlas, you have a great
tool to rely on called TexturePacker, also introduced in this chapter.
Sprite batching is a technique for speeding up the drawing of sprites. As the name im-
plies, batching sprites allows the GPU to render all the sprites in one go (or in technical
terms, in one draw call). It speeds up drawing identical sprites but is most effective
when using a texture atlas. If you use a texture atlas along with sprite batching, you can
draw all the images in that texture atlas in one draw call.
A draw call is the process of transmitting the necessary information to the graphics
hardware in order to render a texture or parts of it. For example, when you're using the
spriteFromFile method to create a CCSprite node, that sprite creates one draw
call. The CPU overhead for issuing each draw call can add up so much that it can de-
crease the framerate, particularly when you want to display more sprites.
CCSpriteBatchNode functions like an extra layer to which you can add sprite
nodes, as long as they all use the same texture. From then on, all the sprite children of
the CCSpriteBatchNode are drawn with a single draw call. Effectively, the CPU
tells the GPU what texture it should draw from but also passes a long list of frames and