com.jmex.game.state
Class GameStateNode<G extends GameState>

java.lang.Object
  extended by com.jmex.game.state.GameState
      extended by com.jmex.game.state.GameStateNode<G>
Direct Known Subclasses:
BasicGameStateNode, GameStateManager

public class GameStateNode<G extends GameState>
extends GameState

GameStateNode maintains a list of other GameStates to process (update and render). It's typically good for handling groups of GameStates that you want to process together. A concrete example would be an ingame state together with an ingame-menu state.

Due to it extending GameState, you can attach other GameStateNodes, forming a tree structure.

Author:
Per Thulin

Field Summary
protected  java.util.ArrayList<G> children
          Contains all the maintained children.
 
Fields inherited from class com.jmex.game.state.GameState
active, name, parent
 
Constructor Summary
GameStateNode(java.lang.String name)
          Creates a new GameStateNode with a given name.
 
Method Summary
 void activateAllChildren()
          Will call setActive(true) on all GameStates maintained.
 void activateChildNamed(java.lang.String name)
          Activates the first child found with a given name.
 void attachChild(G state)
          Attaches a child to this node.
 void cleanup()
          Will perform cleanup on and detach all maintained GameState's.
 void deactivateAllChildren()
          Deactivates all maintained children contained by this GameStateNode.
 void deactivateChildNamed(java.lang.String name)
          Deactivates the first child found with a given name.
 void detachAllChildren()
          Detaches all children of this GameStateNode.
 void detachChild(GameState state)
          Detaches a given child.
 void detachChild(int i)
          Detaches a child at a given index.
 void detachChild(java.lang.String name)
          Detaches the first child found with a given name (case sensitive).
 G getChild(int i)
          getChild returns a child at a given index.
 GameState getChild(java.lang.String name)
          getChild returns the first child found with exactly the given name (case sensitive).
 java.util.ArrayList<G> getChildren()
          Returns the list of GameStates maintained by this GameStateNode.
 int getQuantity()
          getQuantity returns the number of children this node maintains.
 boolean hasChild(G state)
          Determines if the provided GameState is contained in the children list of this node.
 void render(float tpf)
          Renders all maintained children (calling their render method).
 void update(float tpf)
          Updates all maintained children (calling their update method).
 
Methods inherited from class com.jmex.game.state.GameState
getName, getParent, isActive, setActive, setName, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

children

protected java.util.ArrayList<G extends GameState> children
Contains all the maintained children.

Constructor Detail

GameStateNode

public GameStateNode(java.lang.String name)
Creates a new GameStateNode with a given name.

Parameters:
name - The name of this GameStateNode.
Method Detail

update

public void update(float tpf)
Updates all maintained children (calling their update method).

Specified by:
update in class GameState
Parameters:
tpf - The elapsed time since last frame.

render

public void render(float tpf)
Renders all maintained children (calling their render method).

Specified by:
render in class GameState
Parameters:
tpf - The elapsed time since last frame.

cleanup

public void cleanup()
Will perform cleanup on and detach all maintained GameState's.

Specified by:
cleanup in class GameState

attachChild

public void attachChild(G state)
Attaches a child to this node. This node will become the child's parent.

Parameters:
state - The child to attach.

detachChild

public void detachChild(GameState state)
Detaches a given child.

Parameters:
state - The child to detach.

detachChild

public void detachChild(java.lang.String name)
Detaches the first child found with a given name (case sensitive).

Parameters:
name - The name of the child to detach.

detachChild

public void detachChild(int i)
Detaches a child at a given index.

Parameters:
i - The index of the child to be detached.

detachAllChildren

public void detachAllChildren()
Detaches all children of this GameStateNode.


getChildren

public java.util.ArrayList<G> getChildren()
Returns the list of GameStates maintained by this GameStateNode.

Returns:
The list of GameStates maintained by this GameStateNode.

getChild

public GameState getChild(java.lang.String name)
getChild returns the first child found with exactly the given name (case sensitive).

Parameters:
name - the name of the child to retrieve.
Returns:
the child if found, or null.

getChild

public G getChild(int i)
getChild returns a child at a given index.

Parameters:
i - The index to retrieve the child from.
Returns:
The child at a specified index.

getQuantity

public int getQuantity()
getQuantity returns the number of children this node maintains.

Returns:
The number of children this node maintains.

hasChild

public boolean hasChild(G state)
Determines if the provided GameState is contained in the children list of this node.

Parameters:
state - the GameState object to check.
Returns:
true if the object is contained, false otherwise.

activateAllChildren

public void activateAllChildren()
Will call setActive(true) on all GameStates maintained.


deactivateAllChildren

public void deactivateAllChildren()
Deactivates all maintained children contained by this GameStateNode.


activateChildNamed

public void activateChildNamed(java.lang.String name)
Activates the first child found with a given name. Just a wrapper for getChild(name).setActive(true).

Parameters:
name - The name of the GameState to activate.

deactivateChildNamed

public void deactivateChildNamed(java.lang.String name)
Deactivates the first child found with a given name. Just a wrapper for getChild(name).setActive(false).

Parameters:
name - The name of the GameState to deactivate.