Version 2, last updated by ChadyG at April 25, 2010 19:05 UTC

    All logic and asset management utilities exist within a game state.  These states are stored within the core of the engine in a stack, where the topmost state has priority.  This approach disallows having two active states that can be switched between, however until the need for this functionality is needed the current setup is fine.

    Right now there are three different states:

  • Title State
  • Menu State
  • Gameplay State

The title state displays a series of images fading between.  It is a basic state and is only designed to be used at game startup for logos of middleware and title sequences.

The menu state acts as a central hub for the game, allowing the player to manage his data, access stats etc.  It can either be used with the User_Interfaces functionality and support UI configuration files or be completely custom.  (Right now I prefer the latter)

The gameplay state handles all the interesting things such as managing player data, loading levels, game simulation, creating a render context with the Parallax_Rendering functionality among other things.  

 

A Closer Look

Each state contains six actions not including the C++ constructor used by the state manager.  These actions are called over the lifetime of the state and determine its current state (a state with a state!).  

init()

This is called once at the start of the state's life, it is used as a deferred constructor to allow a state to be created and placed into the state queue before it becomes active.  In this action you should initialize all components and data needed for your state.

cleanup()

This is called at the end of the state's life to do the very opposite of init().

pause()

This action is called when a state loses focus.  This allows you to halt any time dependent processes, free up excess memory, or save a temporary state.

resume()

The corollary to pause.  If you have any data or process that needs to be restarted upon reactivation of the state, this is the place to do so.

update()

This is the update callback for the game logic.  In this action you should place all of your game logic that pertains to this state.

draw()

This is called after every call to update.  This is the place to put all render calls for your state.