Build 2D browser games with the Phaser framework. Using Bash's game-kit-2d when a space offers it, otherwise project setup and game config, scenes and their lifecycle (preload, create, update), loading assets and atlases, sprites, animations, Arcade physics (bodies, colliders, overlap, groups and pooling), tilemaps from Tiled, cameras, input (keyboard, pointer, gamepad), sound, UI and text, sca...
Download skill (.zip) Files on GitHubPhaser game development
In Bash: if the space offers game-kit-2d (Phaser), use it and follow its skill. It has the project layout and conventions. This skill covers Phaser itself.
Setup (no kit)
import Phaser from "phaser"; // npm i phaser (pin the version), or a vendored phaser.esm.js
new Phaser.Game({
type: Phaser.AUTO, parent: "game", backgroundColor: "#1d1d2b",
pixelArt: true, roundPixels: true, // for pixel art
scale: { mode: Phaser.Scale.FIT, autoCenter: Phaser.Scale.CENTER_BOTH, width: 960, height: 540 },
physics: { default: "arcade", arcade: { gravity: { y: 1600 }, debug: false, fixedStep: true } },
input: { gamepad: true, activePointers: 3 }, // multi-touch
scene: [Boot, Preload, Title, Play, UI, GameOver],
});
Scenes
preload()loads,create()builds,update(time, delta)runs every frame (delta in ms).- Switch:
this.scene.start("Play", data). Overlay:this.scene.launch("UI")(HUD in its own scene), pause:this.scene.pause()+launch("Pause"). - Clean up in
this.events.once("shutdown", …): timers, listeners on other scenes, global events.
Core patterns
// assets: this.load.atlas("hero", "assets/img/hero.png", "assets/img/hero.json"); this.load.tilemapTiledJSON("l1", "assets/data/level-01.json")
this.anims.create({ key: "run", frames: this.anims.generateFrameNames("hero", { prefix: "run_", end: 5 }), frameRate: 12, repeat: -1 });
const player = this.physics.add.sprite(100, 100, "hero").setCollideWorldBounds(true);
const map = this.make.tilemap({ key: "l1" }), tiles = map.addTilesetImage("tiles", "tiles"), ground = map.createLayer("ground", tiles);
ground.setCollisionByProperty({ solid: true }); this.physics.add.collider(player, ground);
const bullets = this.physics.add.group({ maxSize: 200 }); // pooled: bullets.get(x, y, "bullet")
this.physics.add.overlap(bullets, enemies, (b, e) => { b.disableBody(true, true); hit(e); });
this.cameras.main.startFollow(player, true, 0.12, 0.12).setBounds(0, 0, map.widthInPixels, map.heightInPixels);
const keys = this.input.keyboard.addKeys("W,A,S,D,SPACE,LEFT,RIGHT,UP");
Rules
- Game logic in your own modules where possible (rules, numbers in config), Phaser for rendering, physics and input.
- Movement feel: Arcade
setDrag,setMaxVelocity, plus coyote time and jump buffer by hand (player-movement ideas). - Touch: on-screen buttons as interactive images (
setInteractive(),pointerdown/pointerup) or a virtual joystick plugin. - Audio unlocks automatically on first input; respect mute settings (
this.sound.mute). - Text: bitmap fonts for pixel art;
this.add.textwithresolution: 2for crisp normal text. - Arcade physics with
fixedStep: truekeeps behavior consistent across refresh rates.
Pitfalls
Using delta as seconds (it’s ms), creating objects in update, forgetting shutdown cleanup (duplicate listeners on restart),
this lost in callbacks (use arrow functions), and Scale.RESIZE without handling layout changes. Phaser is WebGL by default:
verify in the viewer’s preview, not the sandbox browser (or set type: Phaser.CANVAS for sandbox playtests).