I am making a “survival” level which lasts 2 minutes. I would like to make a timer appear in the top middle section of the screen.
I figured out how to time the delay event timer, but what I still need to do is display the countdown in MM:SS format as the timer ticks away. I did this before in Phaser 2, but it’s not entirely the same for Phaser 3…
You’ll just need to get the progress of the timer (.getProgress) in your update method, and call a function that updates your timer display based on that data.
I’m not sure if there is built in code for this, however some division and modulus did the trick for me. Try this:
let timeLeft = 120; //Time in total seconds
let seconds = Math.floor(timeLeft % 60); //Seconds to display
let minutes = Math.floor(timeLeft / 60); //Minutes to display