Phaser — Fast & Fun HTML5 Game Framework
Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers. Canvas and WebGL rendering, physics systems (Arcade, Matter.js), sprite atlases, tilemaps, and animation built in.
What it is
Phaser is an open-source 2D game framework for building HTML5 games that run in desktop and mobile web browsers. It provides Canvas and WebGL rendering, multiple physics engines (Arcade and Matter.js), sprite atlases, tilemaps, tweens, and a full animation system out of the box.
Game developers, hobbyists, and educators who want to ship browser-based games without a native build pipeline benefit most. Phaser handles the rendering loop, input, audio, and physics so you focus on game logic.
How it saves time or tokens
Phaser abstracts away the boilerplate of setting up a game loop, managing the DOM canvas, handling cross-browser input events, and implementing collision detection. A developer can go from zero to a playable prototype in under an hour. The framework ships with loaders for spritesheets, audio, tilemaps (Tiled editor format), and bitmap fonts -- assets load through a declarative preload phase rather than manual fetch calls.
How to use
- Install Phaser via npm or include the CDN script:
npm install phaser
- Create a game config and scene:
import Phaser from 'phaser';
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
physics: { default: 'arcade' },
scene: { preload, create, update }
};
function preload() {
this.load.image('sky', 'assets/sky.png');
this.load.spritesheet('player', 'assets/player.png', { frameWidth: 32, frameHeight: 48 });
}
function create() {
this.add.image(400, 300, 'sky');
this.player = this.physics.add.sprite(100, 450, 'player');
this.player.setCollideWorldBounds(true);
}
function update() {
const cursors = this.input.keyboard.createCursorKeys();
if (cursors.left.isDown) this.player.setVelocityX(-160);
else if (cursors.right.isDown) this.player.setVelocityX(160);
else this.player.setVelocityX(0);
}
new Phaser.Game(config);
- Open
index.htmlin a browser. The game runs immediately with physics, input, and rendering handled by Phaser.
Example
// Add a group of collectible stars with arcade physics
const stars = this.physics.add.group({
key: 'star',
repeat: 11,
setXY: { x: 12, y: 0, stepX: 70 }
});
stars.children.iterate((child) => {
child.setBounceY(Phaser.Math.FloatBetween(0.2, 0.4));
});
// Collision detection between player and stars
this.physics.add.overlap(this.player, stars, collectStar, null, this);
function collectStar(player, star) {
star.disableBody(true, true);
score += 10;
}
Related on TokRepo
- Coding Tools -- Developer tools and frameworks curated on TokRepo
- Featured Workflows -- Top-rated assets across all categories
Common pitfalls
- Phaser 3 and Phaser 2 (CE) have incompatible APIs. Tutorials from pre-2018 likely reference Phaser 2 syntax. Always check the version in examples.
- WebGL mode is faster but may not work on older mobile browsers. Use
Phaser.AUTOto let the framework fall back to Canvas when needed. - Large spritesheets without texture atlases waste GPU memory. Use tools like TexturePacker to combine sprites into atlases for production games.
Frequently Asked Questions
Yes. Phaser is released under the MIT license. You can use it for commercial games without royalties or attribution requirements. The framework is fully open source with the codebase hosted on GitHub.
Yes. Phaser targets both desktop and mobile web browsers. It handles touch input, device orientation, and responsive scaling. Performance depends on the device GPU, but Arcade physics games run well on modern smartphones.
Phaser 3 ships with Arcade Physics (lightweight, AABB-based, good for platformers) and Matter.js integration (full rigid-body physics with polygons, constraints, and joints). Arcade is simpler and faster; Matter.js handles complex simulations.
Yes. Phaser ships with TypeScript type definitions. Install via npm and import directly into TypeScript projects. The type definitions cover the full API including scenes, game objects, physics bodies, and input events.
Phaser outputs HTML5 that runs directly in browsers with no plugin or install. Unity requires a WebGL export and produces larger bundles. Phaser is lighter for simple 2D games. Unity is better for complex 3D or when targeting native platforms beyond the web.
Citations (3)
- Phaser GitHub Repository— Phaser provides Canvas and WebGL rendering with Arcade and Matter.js physics
- Phaser Official Website— Phaser is MIT-licensed and free for commercial use
- Phaser 3 Documentation— Phaser 3 API and scene-based architecture
Related on TokRepo
Discussion
Related Assets
NAPI-RS — Build Node.js Native Addons in Rust
Write high-performance Node.js native modules in Rust with automatic TypeScript type generation and cross-platform prebuilt binaries.
Mamba — Fast Cross-Platform Package Manager
A drop-in conda replacement written in C++ that resolves environments in seconds instead of minutes.
Plasmo — The Browser Extension Framework
Build, test, and publish browser extensions for Chrome, Firefox, and Edge using React or Vue with hot-reload and automatic manifest generation.