This page is work-in-progress. You can reach me on twitter or mail to rezoner1337@gmail.com

Playground - States

States are easy way to split application in smaller bits such as menu, game, options.

MyState = {

  create: function() {

    /* application enters this state for the first time */

    this.app; /* << reference to application */

  },

  enter: function() {

    /* application enters this state */

  },

  leave: function() {

    /* application leaves this state */

  },

  /* state can handle events in the same way as application */

  step: function(dt) {

  },

  render: function(dt) {

  },

  mousedown: function() {

  }

};

To switch application state use

playground({

  ready: function() {

    this.setState(NAMESPACE.MyState);

  }

});

To access application from inside the state (without using globals) one can use this.app reference.

Also there are two types of state in playground.

Persistent

MyState = { 

  /* properties */

};

Temporary

Such state will get instantiated (new MyState) every time application enters it.

MyState = function() {

};

MyState.protoype = {

  /* properties */

};

Ask question:

Fork me on GitHub