Jump to content

How to setTimeout with local functions ?


bluedot
 Share

Recommended Posts

It may be a Javascript thing, but I can't do the following in an object.

 

setTimeout(function(){this.startGame();}, 5000);

 

Should I replace "this" with the fully qualified name ? e.g. game.state.states.MyGame.startGame()

 

Thanks.

Link to comment
Share on other sites

Don't use setTimeout in Phaser - under the hood Phaser has some quite specific time requirements, so using Phaser's Timer events instead will prevent a lot of headaches with things happening out of sequence:

game.time.events.add(5000, function() {  this.startGame();}, this);

The last parameter is the context the function will be called in. In this case, it's the same context as that the event is being created in.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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