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


  • Recently Browsing   0 members

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