Recent Resources
-
GLSL 4.0: Discarding Fragments to Create a Perf...
-
GLSL 4.0: Using Subroutines to Select Shader Fu...
-
Building a Complete Board-based Puzzle Game wit...
-
JIRA: Programming Workflows
-
.NET Generics 4.0: Container Patterns and Best...
-
Raw Meat: Game Design Tips from Team Meat's...
-
Sedge: An Automated Error Reporting Tool
A Data-driven Animation Manager
By Diego B.S. | Published Oct 20 2009 08:07 PM in General Programming
Introduction
An animated character in a game is usually made up of more than one animation sequence. These sequences (or states) normally represent a distinct movement of the character, such as jumping or walking. When the sequences are chained together in game they provide a realistic animation. For example a character may run, then jump followed by a skid when they land, this whole animation could be created by chaining 3 or 4 separate sequences. As game development progresses characters can gain extra sequences (e.g. jumping and shooting) and sometimes a series of events may force you to make a decision about which animation should be played, do we perform the rolling animation when the character lands, or the skidding animation? If these decisions are hard coded into the game logic, they can be troublesome to alter.
This article explains a simple data driven animation manager which is designed to make adding/removing animations easy, without requiring heavy changes to the code.
The manager is a layer between the game state and the graphics engine. It takes as input the character state, and as output it plays the right animation sequence from the character animation set. It can be used in combination with any engine.
Implementation
To keep the explanation simple, we are going to use plain C-style enums to represent states and events. A more elegant implementation could be achieved in higher level languages (such as C++) with a signal/slot implementation or member function pointers (e.g. boost::signals, boost::function). Also dictionary style data types (e.g. std::map, std::tr1::unordered_map) could simplify the implementation. Some graphic engines have an index number for each animation sequence .Each state of the manager can match an animation sequence, this way we don´t need to define our own, duplicated states.
We need access to an array of states that the character can be in, and also a list of all the possible triggers that may cause that state to change. These states and events are used in the event table.
The key to the animation manager is an event table which holds the following values:
- The initial animation sequence ( this event can only be triggered from this state).
- The change condition (what happened that would cause this sequence to change?)
- A priority (if the conditions of several animations are fulfilled in the same game frame, which to use?)
- A final animation sequence


















