com.jmex.game.state
Class GameState

java.lang.Object
  extended by com.jmex.game.state.GameState
Direct Known Subclasses:
BasicGameState, GameStateNode, LoadingGameState

public abstract class GameState
extends java.lang.Object

A GameState is used to encapsulate a certain state of a game, e.g. "ingame" or "main menu".

A GameState can be attached to a GameStateNode, forming a tree structure similar to jME's scenegraph.

It contains two important methods: update(float) and render(float), which gets called by the parent GameStateNode, e.g. the GameStateManager.

Author:
Per Thulin
See Also:
GameStateManager, GameStateNode, BasicGameState, CameraGameState

Field Summary
protected  boolean active
          Flags whether or not this GameState should be processed.
protected  java.lang.String name
          The name of this GameState.
protected  GameStateNode parent
          GameState's parent, or null if it has none (is the root node).
 
Constructor Summary
GameState()
           
 
Method Summary
abstract  void cleanup()
          Gets performed when cleanup is called on a parent GameStateNode (e.g.
 java.lang.String getName()
          Returns the name of this GameState.
 GameStateNode getParent()
          Retrieves the parent of this GameState.
 boolean isActive()
          Returns whether or not this GameState is updated and rendered.
abstract  void render(float tpf)
          Gets called every frame after update(float) by the GameStateManager.
 void setActive(boolean active)
          Sets whether or not you want this GameState to be updated and rendered.
 void setName(java.lang.String name)
          Sets the name of this GameState.
 void setParent(GameStateNode parent)
          Sets the parent of this node.
abstract  void update(float tpf)
          Gets called every frame before render(float) by the parent GameStateNode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected java.lang.String name
The name of this GameState.


active

protected boolean active
Flags whether or not this GameState should be processed.


parent

protected GameStateNode parent
GameState's parent, or null if it has none (is the root node).

Constructor Detail

GameState

public GameState()
Method Detail

update

public abstract void update(float tpf)
Gets called every frame before render(float) by the parent GameStateNode.

Parameters:
tpf - The elapsed time since last frame.

render

public abstract void render(float tpf)
Gets called every frame after update(float) by the GameStateManager.

Parameters:
tpf - The elapsed time since last frame.

cleanup

public abstract void cleanup()
Gets performed when cleanup is called on a parent GameStateNode (e.g. the GameStateManager).


setActive

public void setActive(boolean active)
Sets whether or not you want this GameState to be updated and rendered.

Parameters:
active - Whether or not you want this GameState to be updated and rendered.

isActive

public boolean isActive()
Returns whether or not this GameState is updated and rendered.

Returns:
Whether or not this GameState is updated and rendered.

getName

public java.lang.String getName()
Returns the name of this GameState.

Returns:
The name of this GameState.

setName

public void setName(java.lang.String name)
Sets the name of this GameState.

Parameters:
name - The new name of this GameState.

setParent

public void setParent(GameStateNode parent)
Sets the parent of this node. The user should never touch this method, instead use the attachChild method of the wanted parent.

Parameters:
parent - The parent of this GameState.

getParent

public GameStateNode getParent()
Retrieves the parent of this GameState. If the parent is null, this is the root node.

Returns:
The parent of this node.