Sign in to follow this  

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.





Share this post

Link to post
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'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.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.