mattbrand Posted October 25, 2016 Share Posted October 25, 2016 I have 2 timers in my game - an overall game timer, which I display the value on the screen, and a cooldown timer, for when the player does an action, and they have to wait the cooldown duration until they can do another action. My problem is that when I set the cooldown timer, the display of the overall game timer shows the cooldown timer, just briefly. I set the main timer with: gameTimer = game.time.events.add(Phaser.Timer.SECOND * 90, gameOver, this); I display the main timer duration on the screen with: timerText.setText("Time: " + formatTime(game.time.events.duration)); And I set the cooldown timer with another timer variable: var timer = game.time.events.add(Phaser.Timer.SECOND * 0.2, resetCooldown, this); I don't understand how to display the main game timer always, without the cooldown timer affecting it. Link to comment Share on other sites More sharing options...
drhayes Posted October 25, 2016 Share Posted October 25, 2016 What about using "gameTimer.duration" in there instead of "game.time.events.duration"? Link to comment Share on other sites More sharing options...
mattbrand Posted October 25, 2016 Author Share Posted October 25, 2016 Thanks! It's actually "gameTimer.timer.duration" - but that did the trick! Link to comment Share on other sites More sharing options...
mattbrand Posted October 25, 2016 Author Share Posted October 25, 2016 Actually...I thought it worked, but it still changes the display on the screen to the cooldown when you fire. I am now using this to display the time on screen: gameTimer.timer.duration Any other ideas? Link to comment Share on other sites More sharing options...
samme Posted October 25, 2016 Share Posted October 25, 2016 You actually have two timer events attached to one timer (Phaser's main timer). `game.time.events.duration` is changing depending on which event is coming up next. I think you can calculate the remaining duration with, e.g., gameOverTimerEvent.tick - gameOverTimerEvent.timer._now or maybe gameOverTimeEvent.tick - game.time.time drhayes 1 Link to comment Share on other sites More sharing options...
mattbrand Posted October 25, 2016 Author Share Posted October 25, 2016 OK! Yes, that did it. In this case I used: gameTimer.tick - gameTimer.timer._now Thank you so much! Link to comment Share on other sites More sharing options...
Recommended Posts