Game Development Reference
In-Depth Information
States are created and added to a state system with a name to identify them.
States can then be selected by calling ChangeState and passing in a state name.
The state system will manage the update and render of the current active state.
Sometimes a state will want to change the active state. For example, a splash
screen usually displays an image or animation and then changes state to the title
screen. For a splash screen state to change state it must have a reference to the
state system.
class SplashScreenState : IGameObject
{
StateSystem _system;
public SplashScreenState(StateSystem system)
{
_system = system;
}
#region IGameObject Members
public void Update(double elapsedTime)
{
// Wait so many seconds then call _system.ChangeState("title_menu")
System.Console.WriteLine("Updating Splash");
}
public void Render()
{
System.Console.WriteLine("Rendering Splash");
}
#endregion
}
Then when creating the state, the StateSystem can be passed into the
constructor.
_system.AddState("splash", new SplashScreenState(_system));
class StateSystem
{
Dictionary<string, IGameObject> _stateStore = new Dictionary<string,
IGameObject>();
IGameObject _currentState = null;
 
Search WWH ::




Custom Search