Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
A simple Phaser game that increases a score when you click a sprite.
import Phaser from 'phaser';
class ClickScene extends Phaser.Scene {
constructor() {
super('ClickScene');
this.score = 0;
}
preload() {
this.load.image('star', 'assets/star.png');
}
create() {
this.star = this.add.sprite(200, 200, 'star').setInteractive();
this.text = this.add.text(10, 10, 'Score: 0', { fontSize: '24px' });
this.star.on('pointerdown', () => this.addScore());
}
addScore() {
this.score++;
this.text.setText('Score: ' + this.score);
}
}
new Phaser.Game({ type: Phaser.AUTO, width: 400, height: 400, scene: [ClickScene] });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.