StateManager Class
A state manager is a container for all the states in a game.
Constructor
Methods
add
-
state
Adds a state to the game, creating one if necessary.
There are 3 ways to use this function to add a state to the manager. The simplest case is to pass a string for the name, and let the manager create a normal gf.State for you with the name you provided. The second usage is to pass a class that is a decendant of gf.State.
For example:
function MyState(game) {
gf.State.call(game, 'some-name');
}
gf.inherit(MyState, gf.State);
game.state.add(MyState); //adds a new instance of your state
The final usage is to pass a state that is already created. In this case the manager will
add the state to the list based on state.name
and set the game to be the manager's game
instance with state.game = this.game
;
Parameters:
-
state
String | Function | StateThe state name, constructor, or state instance to add.
Returns:
The state that was added
destroy
()
Destroys the state manager completely
enable
-
state
Enables a state in the game.
Parameters:
-
state
String | StateThe name of the state to enable, or the state instance itself.
Returns:
Returns itself.
remove
-
state
Removes a state from the game
Parameters:
-
state
String | StateThe name of the state to remove, or the state instance itself.
Returns:
Returns itself.