Jump to content

game.timer.event & scope


Recommended Posts

I have a query about using game.time.events


When I use this, I think I'm losing the scope of where the event is set as this code:

game.time.events.add( 100, this.doStepBoost );

gives this error:


this.doStepBoost is not a function (removing the this doesn't remedy the issue).


I'm sure this is because I'm using the event incorrectly, any pointers as to where I'm going wrong?

Link to comment
Share on other sites

Why not use the callback context, which is the third parameter?

game.time.events.add(100, this.doStepBoost, this);

In this case 'this' in the callback will be set to the third parameter, which is 'this'.

You can also use closures:

var that = this;game.time.events.add(100, this.doStepBoost);

and inside callback:

Link to comment
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.


  • Recently Browsing   0 members

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