Sunday, April 24, 2011

Methods of animation

There are various methods to do animation in a game.  The methods I have encountered are: Frame-based, Key-frame, Procedural, and Physics-based.

Finding one specific name for this method of animation is difficult.  Other equally appropriate names include cel, sprite, and flipbook.  Cel and flipbook are terms from traditional animation.  Cel animation was performed by drawing the moving parts of a frame onto transparent sheets and aligning these sheets on top of each other, on top of a background layer.  A flipbook is a book of pictures which appear to animate as you flip through the pages.  This kind of animation is frequently used to animate sprites in 2D games, so "sprite animation" is also a valid term for it.  Frame-based animation is having a set of pre-rendered frames which are displayed in succession.

The positions and orientations of the various parts of an animated entity are stored with a timestamp.  Each one of these states is called a "key-frame".  The game engine interpolates between these states based on the current time, resulting in a smooth animation rendered in real-time.  Storing animations in this format reduces memory costs while increasing performance costs.  The reduced memory cost (and potentially reduced animator work time) may make this the preferred method over frame-based animation.  If the entity is too complicated to render in real time however, frame-based animation is a better idea.

This method positions and orients based on code, whether as part of the engine or in a script.  For example:
player->pos.x -= 5; // This is procedural animation, although using a loose definition of "animation".
Some may not agree with me on this, but I classify any position/orientation update code as procedural animation.  Collision detection is part of this method.

This is technically a sub-category of procedural animation.  In physics-based animation, the positions and orientations of entities are controlled by the laws of physics (although those laws may be bent or broken in places in order to get the effect you are going for).  The major advantage to this method is that you do not need animators to create animations for you.  However, getting a physics simulation to work well enough for a completely physics-based game would be difficult.

Usually, a 2D sprite-based game will employ frame-based and procedural animation.  Sometimes physics-based is added in there (Angry Birds for the iPhone is an example of such a game).  The physics aren't always obvious though.  For example, using a velocity to adjust the position of the player's character could be considered physics-based animation, although I personally would put that in the grey-zone between procedural and physics-based.

Learning about the differences between key-frame animation and procedural animation gave me the somewhat funny idea of generating the key-frame animation on the fly.  This would technically be key-frame animation, but it would be powered by procedural animation.  Not very useful in practice, but thinking along those lines helped me clarify the differences between the two.

No comments:

Post a Comment