How to create a timer?

I want to create an integer descending timer, that has zeroes on the left, starts with 8100 and ends with 0000. The timer view updates with a difference of 1 second.

8.1s or 2h15m?

create(){
	this.initialTime = 81;
	this.text = this.add.text(32, 32, 'Count: ' + this.format(this.initialTime));
	this.timedEvent = this.time.addEvent({ delay: 1000, callback: this.timerEvent, callbackScope: this, loop: true });

}

format( value ){
	return '0000'.substr(value.toString().length) + value // 81 --> 0081 
}

timerEvent ()
{
    this.initialTime -= 1; 
    this.text.setText('Count: ' + this.format(this.initialTime));
}
1 Like

2h15m