gamvas.state

Helper functions for state management

Summary
gamvas.stateHelper functions for state management
Functions
addStateAdd a state to the state system
setStateswitch to a new state
getStateGet a certain state
getCurrentStateGet the current state

Functions

addState

addState: function(state)

Description

Add a state to the state system

Parameters

statea gamvas.State object

Example

var myState = gamvas.State.extend({
    init: {
        console.log('state '+this.name+' initialized');
    }
});
gamvas.state.addState(new myState('mystate'));

setState

setState: function(stateName)

Description

switch to a new state

Parameters

stateNamethe name of the state to switch to

getState

getState: function(name)

Get a certain state

Parameters

nameName of the state to get

Returns

The gamvas.State or false if state is not existing

Example

var mainState = gamvas.state.getState('main');
if (mainState) {
   console.log("found state main");
}

getCurrentState

getCurrentState: function()

Description

Get the current state

Example

var cs = gamvas.state.getCurrentState();
console.log("current state is: " + cs.name);
addState: function(state)
Add a state to the state system
setState: function(stateName)
switch to a new state
getState: function(name)
Get a certain state
getCurrentState: function()
Get the current state
Game state class, overwrite for own states
Close