Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Phaser timer countdown that updates text every second.
import Phaser from 'phaser';
class TimerScene extends Phaser.Scene {
create() {
this.timeLeft = 10;
this.text = this.add.text(100, 100, 'Time: 10', { fontSize: '32px' });
this.timer = this.time.addEvent({ delay: 1000, callback: this.tick, callbackScope: this, loop: true });
}
tick() {
this.timeLeft--;
this.text.setText('Time: ' + this.timeLeft);
if(this.timeLeft <= 0) {
this.text.setText('Game Over');
this.timer.remove();
}
}
}
new Phaser.Game({ type: Phaser.AUTO, width: 400, height: 200, scene: [TimerScene] });Phaser is a fast, open-source 2D HTML5 game framework used to create browser-based games for desktop and mobile, using JavaScript or TypeScript with WebGL/Canvas rendering.
Origin & Creator
Phaser was created by Richard Davey (Photon Storm) to provide a powerful, accessible, open-source framework for modern HTML5 game creation.
Industrial Note
Phaser dominates the HTML5 gaming market, especially in educational games, advergames, casino & gambling front-ends, interactive marketing campaigns, and lightweight browser-based entertainment.