Phaser HTML5 Game Framework

4.0.0 · active · verified Sun Apr 19

Phaser is a robust, open-source HTML5 game framework designed for creating 2D games across desktop and mobile web browsers, currently stable at version 4.0.0. It leverages WebGL and Canvas rendering and has been under active development for over a decade. Version 4 represents a significant, ground-up rebuild of its WebGL renderer, featuring a new, node-based architecture that replaces the v3 pipeline system for enhanced performance and reliability, while striving to maintain a familiar API for developers. The framework offers an extensive suite of features for 2D game development, including advanced physics engines, sophisticated tweening systems, and web audio management. It supports development using both JavaScript and TypeScript and is compatible with various modern front-end frameworks. The project is commercially developed and maintained by Phaser Studio Inc. with strong community contributions, adhering to a release cadence that includes extensive pre-release candidates for major versions, ensuring a stable and well-tested core.

Common errors

Warnings

Install

Imports

Quickstart

This code sets up a minimal Phaser 4 game with a single scene, displaying a text object and animating a circle using tweens.

import Phaser from 'phaser';

class DemoScene extends Phaser.Scene {
    constructor() {
        super({ key: 'DemoScene' });
    }

    preload() {
        // Load assets here if needed, e.g., this.load.image('logo', 'assets/phaser3-logo.png');
    }

    create() {
        this.add.text(100, 100, 'Hello Phaser 4!', { font: '32px Arial', color: '#ffffff' });
        console.log('Phaser 4 Demo Scene created!');

        // Example: Add a simple tween
        const circle = this.add.circle(400, 300, 50, 0xff0000);
        this.tweens.add({
            targets: circle,
            x: 600,
            duration: 2000,
            ease: 'Power2',
            yoyo: true,
            loop: -1
        });
    }

    update(time: number, delta: number) {
        // Game logic updated every frame
    }
}

const config: Phaser.Types.Core.GameConfig = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    backgroundColor: '#1a1a1a',
    scene: DemoScene,
    parent: 'game-container', // Ensure you have a div with id="game-container" in your HTML
    physics: {
        default: 'arcade',
        arcade: {
            debug: false
        }
    }
};

new Phaser.Game(config);

view raw JSON →