Game Development Reference
In-Depth Information
Sprite Sheets
In order to line up animated sprites properly, it is preferable to have all the sprites
for a particular character be the same size. In the past, many libraries also required
thatallimagefileshaddimensionsthatwerepowersoftwo,inwhichcasea30×30
image would have to be padded to 32×32. Although most modern graphics librar-
ies do allow non-power-of-two textures, power-of-two textures are still preferable
due to a concept known as mipmapping (which is beyond the scope of this topic).
You could certainly have each frame of an animated sprite be an individual image
file (or texture ). Although this is a simple system, it typically ends up wasting a
greatdealofmemory.That'sbecausespritesusuallyaren'trectangles,eventhough
the image file must be. If the size of a particular frame's image file is 100KB,
but 15% of this space unused, that means 15KB is being wasted. This can add up
quickly if there are a lot of frames of an animation; even just 100 total frames (~5
total seconds of animation) would waste almost 1.5MB!
A solution to this problem is to use a single image file that contains all the sprites,
called a sprite sheet . In a sprite sheet, it is possible to pack in the sprites closely
and overlap the unused space. This means that when the sprite sheet is opened, a
bit of work is necessary to reconstruct the correct images in memory. But at least
the file size can be significantly reduced, which will reduce the total installation
size of the game. Figure 2.5 demonstrates saving space with a sprite sheet.
Search WWH ::




Custom Search