Game Development Reference
TurboSquid, the character may come as a single file containing any number
of animation sequences. In the case of 2D sprites, it is not uncommon to find
all the action sequences for one character in a single texture atlas.
3.7.1 Single 2D Sprite Actions
As we've seen, a texture atlas is a convenient and optimizing way to keep
sprites. More often than not, all the animations for a single character are
kept in a texture atlas. This requires pixel management on the part of the
programmer to ensure that the correct part of the texture is displayed at the
right time. Figure 3.15 shows a texture atlas with several idle and walking
animation frames. Although it is not strictly necessary to have the frames
belonging to the same animation next to each other in the texture, it makes it
monumentally easier to program if they are in sequence and packed together.
It's also easier if each frame is the same size. In the image shown, each frame
is 32 × 64.
Individual animations are specified with a starting frame and a number of
frames; for example, the walk left animation starts at frame 3 and is three
frames in length. By knowing the fixed width for a frame, the exact pixel value
for the start of an animation sequence can be calculated. In this case, the walk
left animation begins at frame 3, and therefore the starting x pixel location
would be 3 × 32 = 96.
FIG 3.15 Joined frames for four
separate animations. (Sprite art
thanks to Dezire Soft at http://www
If the sprite atlas does not have power of two dimensions, Unity will
squash and stretch it to make it so. This will produce an undesirable effect
with the frame locations. To correct this, select the texture in the Project
and in the Inspector set the Texture Type to Advanced and the Non Power
of 2 to None, as shown in Figure 3.16 .