Bash.tv → GitHub → itch.io

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 GitHub

Phaser 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

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

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).