Jump to content

Starting state with custom parameter


Recommended Posts



I have a question regarding starting State with custom parameter. From docs i see:

start(key, clearWorld, clearCache, parameter)

Start the given State. 

* Additional parameters that will be passed to the State.init function (if it has one).


There is no init method in State. If i make one in my state will it get called or not? Will init be called before create?


Reason i am asking is that i would like to start state PlayGame with one of these params ['L1', 'L2',  'L3', 'L4' ].

Param will depend on what button user clicks in LevelSelect menu.





Link to comment
Share on other sites

Yes first init gets called, then create, then update, and


function MyState() {}

MyState.prototype = {
   // State init method gets the params here
   init: function(params) {
   create: function() {
       var params = ['L1', 'L2'];
       // you start a new state with parameter like this
       this.game.state.start('my-state', true, false, params);
   update: function() {

Here is a list of other methods you can define in your state:

Note: I think init method should be mentioned there as well.

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...