ScriptsApr 11, 2026·3 min read

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.

TL;DR
Phaser builds 2D games for desktop and mobile browsers with Canvas/WebGL rendering, physics, and built-in animation.
§01

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.

§02

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.

§03

How to use

  1. Install Phaser via npm or include the CDN script:
npm install phaser
  1. 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);
  1. Open index.html in a browser. The game runs immediately with physics, input, and rendering handled by Phaser.
§04

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;
}
§05

Related on TokRepo

§06

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.AUTO to 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

Is Phaser free for commercial games?+

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.

Does Phaser support mobile browsers?+

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.

What physics engines does Phaser include?+

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.

Can I use TypeScript with Phaser?+

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.

How does Phaser compare to Unity for 2D games?+

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)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets