Description of Finite State Machines

A finite state machine (fsm) is a graph in which vertices are represented by states and edges are represented by transition functions between states. In the programming world, the current state of the fsm machine decides what code will be executed. Transitions between states are instantaneous.

FSMs are very suitable for animation coding because they provide a clean way to switch between different animations and prevent undesired transitions from occurring. Roughly speaking, a state is represented by either an animation or a transition from one animation to another.

The Animation.FiniteStateMachine object

In the Animation Component Library, a fsm is represented by the FiniteStateMachine object, which uses strings to represent states. This is an abstract class, and the user is expected to make a subclass of it. The base constructor requires two parameters: the game and the initial state, represented by a string.
  • The abstract method RunCurrentState(GameTime gameTime) is called whenever the FSM updates.
  • The CurrentState property should be used to determine what code is executed.
  • The TimeInState property can also be useful.
  • To transition from one state to another, the Transition(string targetStateName) should be called. Code should be executed right before this method call to simulate the state transition function. Transitions are instantaneous.

Last edited Feb 12, 2007 at 1:47 AM by dastle, version 2


No comments yet.