API Docs for: v0.1.0
Show:

StateManager Class

Extends Object

A state manager is a container for all the states in a game.

Constructor

StateManager

(
  • game
)

Parameters:

  • game Game

    The game this manager bleongs to.

Item Index

Properties

Methods

_createDefault

() State

Creates the default state

Returns:

State:

The default state

add

(
  • state
)
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 | State

    The state name, constructor, or state instance to add.

Returns:

State:

The state that was added

destroy

()

Destroys the state manager completely

enable

(
  • state
)
StateManager chainable

Enables a state in the game.

Parameters:

  • state String | State

    The name of the state to enable, or the state instance itself.

Returns:

StateManager:

Returns itself.

remove

(
  • state
)
StateManager chainable

Removes a state from the game

Parameters:

  • state String | State

    The name of the state to remove, or the state instance itself.

Returns:

StateManager:

Returns itself.

Properties

active

State

The currently active state

count

Number

The count of states in this manager

game

Game

The game instance that this manager belongs to.

states

Object

The states managed by this manager, keyed on the state name