caymanbruce Posted March 10, 2017 Share Posted March 10, 2017 I am using a custom timer to display the remaining time in the game. In the Timer class I have a function to create a timer, and attach a tick function as its parameter. The timer is currently not working and I can't monitor the changes in the ticks. I put a console.log(myTime) inside the timerTick but nothing shows up. constructor(options) { this.totalTime = options.seconds; this.game = options.game; this.onComplete = options.onComplete; const key = options.key || 'timer'; } reset() { if (this.timer) { this.timer.stop(); } this.hasFinished = false; this.timer = this.game.time.create(); this.timer.repeat(Phaser.Timer.SECONDS, this.totalTime, this.timerTick.bind(this), this); this.timer.onComplete.addOnce(() => { this.hasFinished = true; if (this.onComplete) { this.onComplete(); } }); } remainingTime() { return this.totalTime - this.timer.seconds; } timerTick() { const myTime = this.remainingTime(); console.log(myTime); } Link to comment Share on other sites More sharing options...
samme Posted March 10, 2017 Share Posted March 10, 2017 Should be Phaser.Timer.SECOND. Then try game.debug.timer(). Link to comment Share on other sites More sharing options...
caymanbruce Posted March 11, 2017 Author Share Posted March 11, 2017 4 hours ago, samme said: Should be Phaser.Timer.SECOND. Then try game.debug.timer(). Thank you! That works! I have got another problem though. The current timer stops running when the browser window is unfocused. What should I do to make it continue to run even if I am not focusing on the game window? (For example I may switch to my editor's window when playing the game.) Link to comment Share on other sites More sharing options...
samme Posted March 11, 2017 Share Posted March 11, 2017 docs/2.6.2/Phaser.Stage.html#disableVisibilityChange Link to comment Share on other sites More sharing options...
Recommended Posts