Game Development Reference
In-Depth Information
Fig. 26.1
A sequence of images representing a walking motion
Why use animations?— There are different reasons for putting animations in
your games. When you create 3D games, animation is normally necessary to
enhance realism, but for 2D games this is not always the case. Still, animations
can considerably enrich a game.
Animation brings objects to life. But it does not have to be complicated to
do this. The simple animation of a character closing and opening eyes already
results in a strong feeling that the character is alive. Animated characters are
also easier to relate to. If you look at a game like Cut The Ropes, the main
character is simply sitting in a corner. But from time to time the character
makes some funny moves to show you it is there and wants you to bring
it food. This creates a very effective motivation for the player to continue
playing the game.
Animations also help to draw the attention of the player to a certain ob-
ject, task, or event. For example, having a small animation in a button makes
it clearer for the player that she/he has to press the button. And a bouncing
waterdrop or a rotating star indicates more clearly that this object should be
collected or avoided. Animations can also be used to provide feedback. When
a button is actually moving down when you press it with the mouse it is im-
mediately clear that the button press was successful.
However, creating animations is a lot of work. So think carefully before-
hand where animations are needed and where they can be avoided, to save
time and money.
26.3 The Animation Class
For animated characters, we usually design one sprite for each type of movement.
The example in Fig. 26.1 is the sprite for animating a running character. During the
development of the Penguin Pairs game, we already designed the SpriteSheet class
that represents a strip or a sheet of images. Therefore, we are going to use that
class as a base class for a new class, Animation .The sheet index of the Animation
object will then indicate which frame we are currently drawing. When we create an
animation, we need to store some additional information. For example, we would
like to indicate how long each frame should be shown on the screen. We store this
value in a member variable called frameTime :
protected float frameTime;
Search WWH ::




Custom Search