Game Development Reference
In-Depth Information
means 10 draw calls at a minimum, which is less than ideal. Organizing your images
may require some thought, but it's well worth it.
Unlike code, which you should separate into distinct logical components, with a texture
atlas your goal should be to put as many images as possible into the same texture atlas
while trying to reduce the wasted space of each texture atlas as much as possible.
It may seem logical to use one texture atlas for your player's images; another for mon-
ster A, B, and C and their animations; and so on. But that would mean more draw calls.
However, that's helpful only if you have a huge number of images for each game ob-
ject and you want to be selective about which images to load into memory at any one
time. One such scenario might be a shoot-'em-up game with different worlds where
you know that each world has separate types of enemies. In that case, it makes sense to
not mix and match enemies of different worlds into the same texture atlas. Otherwise,
just for organization's sake, you shouldn't split up your texture atlases by game objects
but rather fill each texture atlas as much as possible.
Don't fall into the habit of creating one texture atlas per graphical object because it
seems logical to do so. The best-performing texture atlases are full to the brim with a
great variety of images that can all be rendered with a single sprite batch node.
As long as your game's images can fit into two or three texture atlases of 2048×2048
size, you should just put all the images into those texture atlases and load them up
front. This will use 32MB to 48MB of memory for your textures. Your actual program
code and other assets such as audio files don't take up that much space, so you should
be able to keep these texture atlases in memory even on iOS devices with just 256MB
of memory.
Once you pass that point, however, you need a better strategy to handle your texture
memory. One such strategy, as mentioned earlier, could be to divide your game's im-
ages into worlds and load only the texture atlases needed for the current world. This
will introduce a short delay when a new world is loaded and would be a good use for
the LoadingScene described in Chapter 5 .
Because cocos2d automatically caches all images, you need a way to specifically un-
load textures that you know you don't need. You can rely on cocos2d to do that for
Search Nedrilad ::

Custom Search