Luis Fonseca Posted May 9, 2014 Share Posted May 9, 2014 Hi, I'm using the following code (Typescript) to create a timer and fire an event, but nothing happens. Any idea what might be wrong?private timer:Phaser.Timer;...this.timer = new Phaser.Timer(this.game, false);this.timer.add(counter, this.onTimerComplete, this);this.timer.start();private onTimerComplete():void{ console.log("Timer complete");} Link to comment Share on other sites More sharing options...
stasuss Posted May 9, 2014 Share Posted May 9, 2014 Try doing in this way:game.time.events.add(counter, this.onTimerComplete, this);In this case you do not need to start it. Link to comment Share on other sites More sharing options...
Luis Fonseca Posted May 9, 2014 Author Share Posted May 9, 2014 The problem is that I want to be able to start it, pause it and resume it. Do you know why the code I posted doesn't work? Link to comment Share on other sites More sharing options...
stasuss Posted May 9, 2014 Share Posted May 9, 2014 if you want to have control, use this approach:var timer = game.time.create(false);timer.add(counter, onTimerComplete, this);timer.start();I don't know why you code is not working. Perhaps some additional setup is required. I'm going to see the sources now EDIT:timers created using factory are automaticaly updated like this:this._timers[this._i].update(this.now) Link to comment Share on other sites More sharing options...
Luis Fonseca Posted May 9, 2014 Author Share Posted May 9, 2014 Thanks mate! That seems to work. But still no idea why the other approach doesn't. I'll try to investigate it as well and I see if I find anything. Link to comment Share on other sites More sharing options...
rich Posted May 9, 2014 Share Posted May 9, 2014 The other approach doesn't work because the Timers update method never gets called. Either create it via the factory, or in your States update method call Timer.update directly (passing in the current timestamp). Also note that creating one directly means it won't pause on game-pause events, etc. For that you should use the factory. Link to comment Share on other sites More sharing options...
Luis Fonseca Posted May 9, 2014 Author Share Posted May 9, 2014 Great! Thanks for the explanation! Link to comment Share on other sites More sharing options...
Recommended Posts