com.jme.app
Class GameStateManager

java.lang.Object
  extended bycom.jme.app.GameStateManager

public class GameStateManager
extends java.lang.Object

A manager to handle multiple game states. The game states are binded to strings that function as keys. Only the active game state gets updated. Use switchTo(String) to switch the active game state.

Author:
Per Thulin

Method Summary
 void addGameState(java.lang.String name, GameState state)
          Binds a name/key to a .
 void cleanup()
          Performs cleanup on all loaded game states.
static GameStateManager create(Node rootNode)
          Creates a new GameStateManager connected to the passed rootNode.
static GameStateManager getInstance()
          Returns the singleton instance of this class.
 void removeGameState(java.lang.String name)
          Removes a GameState, meaning that we call its cleanup() and removes it from the hashmap.
 void render(float tpf)
          Renders the current/active game state.
 void switchTo(java.lang.String name)
          Switches to a GameState, meaning that we detatch the active states node and attaches the new ones instead.
 void update(float tpf)
          Updates the current/active game state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static GameStateManager create(Node rootNode)
Creates a new GameStateManager connected to the passed rootNode.

Parameters:
rootNode - The root of the scene graph.
Returns:
If this is the first time create() is called, a new instance will be created and returned. Otherwise one should use getInstance() instead.

getInstance

public static GameStateManager getInstance()
Returns the singleton instance of this class. Note that create() has to have been called before this.

Returns:
The singleton.

addGameState

public void addGameState(java.lang.String name,
                         GameState state)
Binds a name/key to a . Note that this doesn't make the passed game state the active one. In order for that, you'd have to call switchTo(String).

Parameters:
name - The name/key of the Game State to add.
state - The GameState to bind to the passed name.

removeGameState

public void removeGameState(java.lang.String name)
Removes a GameState, meaning that we call its cleanup() and removes it from the hashmap. It also runs the garbage collector.

Parameters:
name - The name/key of the Game State to remove.

switchTo

public void switchTo(java.lang.String name)
Switches to a GameState, meaning that we detatch the active states node and attaches the new ones instead. We also set the new states Camera to our Renderer. If there is an active ISoundRenderer it also receives the new Camera.

Parameters:
name - The name/key of the game state to switch to.

update

public void update(float tpf)
Updates the current/active game state. Should be called every frame.

Parameters:
tpf - The time since last frame.

render

public void render(float tpf)
Renders the current/active game state. Should be called every frame.

Parameters:
tpf - The time since last frame.

cleanup

public void cleanup()
Performs cleanup on all loaded game states. Should be called before ending your application.