phaser-core
gamedev-skills/awesome-gamedev-agent-skills
Set up and debug Phaser 4 games: Game config, Scene lifecycle, asset loading, cameras, and cross-scene communication.
What is phaser-core?
Phaser-core provides the foundation for building Phaser games, covering the Game configuration, Scene lifecycle (init/preload/create/update), asset loading, camera control, and data passing between scenes. Use this when starting a Phaser project, structuring scenes, loading assets, or debugging scene transitions and shared state.
- Configure the Phaser.Game with type, dimensions, scale, and scene array
- Implement the Scene lifecycle: init() for state reset, preload() for asset queuing, create() for setup, and update() for frame logic
- Load and cache assets per-scene, with global cache access across all scenes
- Control cameras with bounds, follow targets, and zoom levels
- Manage cross-scene communication via the global registry or scene event emitters
- Transition between scenes using start(), launch(), switch(), pause(), and sleep()
How to install phaser-core
npx skills add https://github.com/gamedev-skills/awesome-gamedev-agent-skills --skill phaser-core- Node.js and npm installed
- Phaser 4.2 (or existing Phaser 3.90 project) in package.json
- Basic understanding of ES modules and class inheritance
How to use phaser-core
- 1.Check package.json and lockfile to detect the installed Phaser major version
- 2.Create a Game config object with type, width, height, and scene array, then instantiate new Phaser.Game(config)
- 3.Define each screen as a Scene subclass with a unique key and implement init(), preload(), create(), and update() methods
- 4.Queue all assets in preload() and use them in create() or update()
- 5.Reset per-run state in init(), not the constructor, to avoid stale values on scene restart
- 6.Use this.scene.start/launch/switch/sleep/wake to transition between scenes and this.registry to share global data
- 7.Test by serving the page, confirming assets load in the Network tab, and verifying scenes switch as expected
Use cases
- Starting a new Phaser 4 game with proper Game config and initial Scene structure
- Debugging asset loading issues by confirming preload() queuing and create() availability
- Implementing screen transitions (menu → gameplay → game-over) with data passing
- Building a HUD overlay that runs alongside the main game scene using launch()
- Setting up a camera that smoothly follows the player through a larger world
- Game developers building 2D games with Phaser
- Developers migrating from Phaser 3 to Phaser 4
- Teams structuring multi-scene games with shared state
phaser-core FAQ
Use Phaser 4.2 for new projects. Do not silently rewrite an existing Phaser 3 project as Phaser 4 unless the user explicitly requests migration.
You either forgot to queue them in preload() or used the wrong key. The loader runs between preload() and create(); assets are not available until create() starts.
Use this.registry.set/get for global data accessible from any scene, or emit events on a specific scene's event emitter via this.scene.get('key').events.emit().
start() stops the current scene and starts the target; launch() runs the target alongside the current scene (useful for overlays); switch() sleeps the current scene and starts/wakes the target.
Use phaser-arcade-physics for velocity, gravity, colliders, overlap checks, and physics groups. Use phaser-core for the Game setup, Scene structure, assets, and cameras.
Full instructions (SKILL.md)
Source of truth, from gamedev-skills/awesome-gamedev-agent-skills.
name: phaser-core description: > Set up and debug a Phaser 4 game: the Game config, the Scene lifecycle (init/preload/create/update), the asset loader, cameras, and cross-scene communication. Use when building or debugging a Phaser game — when the user mentions Phaser, Phaser.Game, Phaser.Scene, preload/create/update, this.load, this.add, or scene transitions. For Arcade Physics movement/collisions use phaser-arcade-physics.
Phaser 4 Core
Set up the foundation of a Phaser game: the Game config, the Scene
lifecycle, asset loading, cameras, and passing data between scenes. Targets
Phaser 4.2 for new projects; keep an existing Phaser 3.90 project on its
pinned major unless the user explicitly asks for a migration.
When to use
- Use when starting a Phaser game, wiring the
Phaser.Gameconfig, structuringScenes, loading assets inpreload, or fixing scene transitions and shared state. - Use when the project has
phaserinpackage.jsonorimport Phaser from 'phaser', and code usespreload()/create()/update().
When not to use: movement, velocity, colliders, gravity, or overlap → use
phaser-arcade-physics. Complex rigid-body simulation uses Matter physics (a
separate concern). For cross-engine save/load patterns use save-systems.
Core workflow
- Detect the installed major first. Read
package.jsonand the lockfile. Use Phaser 4.2 for new work; do not silently rewrite a Phaser 3 project as Phaser 4. - Create the game from a config.
new Phaser.Game(config)withtype: Phaser.AUTO(WebGL with Canvas fallback), awidth/height, and ascenearray. The first scene (and any withactive: true) starts automatically. - Model each screen as a
Scene. SubclassPhaser.Scene, pass a uniquekeytosuper, and implement the lifecycle:init(data)→preload()→create(data)→update(time, delta). - Load assets in
preload, use them increate. Queued assets are not available untilcreate. The loader is per-scene; the cache it fills is global. - Reset per-run state in
init(), not the constructor. A scene instance is reused across restarts, so constructor-set fields keep stale values. - Move between screens with
this.scene.start/launch/switch/sleep/wake. Share data throughthis.registry(global) or a sibling scene's event emitter. - Run and observe. Serve the page, open it, and confirm assets load (watch the Network tab and console) and scenes switch as expected before assuming success.
Patterns
1. Game config + boot (ES module)
// main.js — one Game owns the renderer, loop, cache, and Scene Manager.
import Phaser from 'phaser';
import BootScene from './scenes/BootScene.js';
import PlayScene from './scenes/PlayScene.js';
const config = {
type: Phaser.AUTO, // WebGL if available, else Canvas
width: 800,
height: 600,
backgroundColor: '#1d1d28',
scale: { mode: Phaser.Scale.FIT, autoCenter: Phaser.Scale.CENTER_BOTH },
scene: [BootScene, PlayScene] // BootScene starts first
};
new Phaser.Game(config);
2. A Scene with the full lifecycle
// scenes/PlayScene.js
import Phaser from 'phaser';
export default class PlayScene extends Phaser.Scene {
constructor() {
super('play'); // unique scene key
}
init(data) {
// Reset run-specific state HERE so restarts start clean.
this.score = 0;
this.level = data.level ?? 1;
}
preload() {
// Queue downloads. Not usable until create().
this.load.image('player', 'assets/player.png');
this.load.spritesheet('coin', 'assets/coin.png', { frameWidth: 16, frameHeight: 16 });
}
create() {
this.player = this.add.sprite(400, 300, 'player');
this.scoreText = this.add.text(10, 10, 'Score: 0', { fontSize: '20px', color: '#fff' });
this.cursors = this.input.keyboard.createCursorKeys();
}
update(time, delta) {
// delta is milliseconds since last frame; divide by 1000 for seconds.
const speed = 200 * (delta / 1000);
if (this.cursors.left.isDown) this.player.x -= speed;
if (this.cursors.right.isDown) this.player.x += speed;
}
}
3. Cross-scene data + events
// The registry is a global DataManager shared by every scene.
this.registry.set('coins', 0); // in any scene
const coins = this.registry.get('coins'); // read anywhere
// React to registry changes (e.g. a HUD scene listening to gameplay):
this.registry.events.on('changedata-coins', (parent, value) => {
this.coinText.setText(`Coins: ${value}`);
});
// Talk directly to another running scene via its event emitter:
const ui = this.scene.get('hud');
ui.events.emit('show-message', 'Level cleared!');
4. Scene transitions (pick the right verb)
this.scene.start('gameover', { score: this.score }); // stop this scene, start target
this.scene.launch('hud'); // run a second scene in parallel (overlay HUD)
this.scene.switch('menu'); // sleep this scene, start/wake target
this.scene.pause(); // freeze updates but keep rendering (modal)
this.scene.sleep(); // stop updating AND rendering, keep state for wake
5. A camera that follows the player
this.cameras.main.setBounds(0, 0, 1600, 1200); // world size
this.cameras.main.startFollow(this.player, true, 0.1, 0.1); // smooth lerp follow
this.cameras.main.setZoom(1.5);
Pitfalls
- Assets are
undefinedincreate/update→ you forgot to queue them inpreload, or used the wrong key. The loader runs betweenpreloadandcreate. - State leaks across a restart → you set fields in the constructor. The Scene
instance is reused; reset run state in
init()and clear arrays onshutdown. this.scene.startvsthis.scene.launch→startstops the calling scene;launchruns the target alongside it. Usingstartfor a HUD hides the game.thisis wrong in a callback → arrow functions keep the Scene'sthis; plainfunctioncallbacks need a context argument or.bind(this).- Phaser 2 tutorials don't work → "States" were renamed to "Scenes" in Phaser 3, and each Scene owns its own systems (input, cameras, tweens) rather than a global Game World.
- Phaser 3 custom pipelines fail in Phaser 4 → Phaser 4 rebuilt the renderer and replaced the old FX/pipeline extension points. Migrate custom shaders and renderer plugins against the Phaser 4 guide; do not mechanically copy internal renderer code.
- Nothing renders / black screen → confirm the canvas mounted,
width/heightare set, and a scene actually started (checkgame.scene.dump()output).
References
- For the full scene state machine (pause/resume vs sleep/wake vs stop/start, the
restart-state bug, and removing/replacing scenes), read
references/scene-flow.md.
Related skills
phaser-arcade-physics— velocity, gravity, colliders, overlap, and groups.input-systems— rebindable, multi-device input architecture (engine-agnostic).pixijs-rendering/threejs-scene-setup— other browser rendering stacks.platformer/puzzle— genre templates that compose Phaser skills.
Related skills
More from gamedev-skills/awesome-gamedev-agent-skills and the wider catalog.

physics-tuning
Tune game physics for stable, responsive motion—fixed timestep, interpolation, CCD, mass/drag, and collision layers.

pixijs-rendering
Set up PixiJS v8 rendering: async Application, asset loading, scene graph, ticker loop, and pointer events.

platformer
Build 2D platformers with tight jump feel: coyote time, jump buffering, variable height, and level structure.

procedural-gen
Generate reproducible game content—terrain, dungeons, and loot—from seeded algorithms and noise.

prototype-fast
Build a playable mechanic prototype in ~1 hour to answer 'is it fun?' with greybox primitives and a hard timebox.

puzzle
Build grid/board puzzle games with deterministic rule resolution, cascades, undo, and level progression.