phaserjs/phaser/scenes
Claude Code and agent skill by phaserjs/phaser
- community
Checking that the SKILL.md file is still in the repository.
Phaser 4 Scenes: the lifecycle (init, preload, create, update), the Scene config, this.scene (start, restart, launch, run, pause, resume, sleep, wake, switch, stop, transition, get), passing data, parallel Scenes, render order, and cleaning up on SHUTDOWN. Use when adding a menu, level, HUD, pause screen or game-over screen, restarting a level, running a UI Scene over the game, passing a score between Scenes, or fading from one Scene to the next. Corrects v3 habits: listeners on this.events, the registry, this.scale and other Scenes survive a restart and pile up; data given to wake or resume never reaches init or create; restart() with no data reuses the old data; launch or run on a running Scene restarts it; map replaces the whole injection map. Triggers on: Scene, this.scene, scene.start, restart, launch, pause, sleep, switch, transition, init, preload, create, update, SHUTDOWN, UI scene, HUD scene, multiple scenes.
Install
npx vskill@latest install phaserjs/phaser/scenesSKILL.md
The same SKILL.md was published earlier as phaserjs/phaser/scenes.
Scenes
How Scenes start and stop, how to run several at once, pass data between them, and clean up when one shuts down.
Source: src/scene/ScenePlugin.js (this.scene), src/scene/SceneManager.js, src/scene/Systems.js (this.sys), src/scene/Settings.js, src/scene/typedefs/SettingsConfig.js, src/scene/events/. Related: phaser4-core, game-setup-and-config, events-system, data-manager, loading-assets.
Quick start
Lifecycle
constructorruns once, when the Scene is added.init(data)runs on every start.STARTandREADYare emitted onthis.eventsjust before it.preload(), then the Loader runs. Files in the Scene config'spackare loaded beforepreload.create(data), after loading. With nopreload, it runs straight afterinit.CREATEis emitted after it.update(time, delta)every frame while the Scene is running.
The status is this.sys.getStatus(): Phaser.Scenes.PENDING (0), INIT, START, LOADING, CREATING, RUNNING (5), PAUSED, SLEEPING, SHUTDOWN, DESTROYED (9).
The Scenes in the game config start when the game emits READY, after the global plugins are installed, and before callbacks.postBoot runs. Since 4.3, that holds for every renderer, including HEADLESS and jsdom tests (#7348). The full boot order is in game-setup-and-config.
Scene config
Pass it to super(), or as the Scene's entry in the game config.
pluginslists the Scene plugins to install:'Clock','DataManagerPlugin','InputPlugin','Loader','TweenManager','LightsPlugin', plus any from the game config. With[],this.time,this.data,this.input,this.load,this.tweensandthis.lightsare all undefined.this.add,this.cameras,this.eventsandthis.sceneare always there.mapreplaces the whole injection map, so every property you leave out, such asthis.addorthis.cameras, is no longer set.mapAddadds properties to the map, but can't rename ones it already has.- A Scene can be an object:
{ key: 'Menu', create () {}, update () {}, extend: { helper () {} } }. The functions inextendbecome Scene properties. - In TypeScript,
this.scene.get<UI>('UI')returns the Scene typed as your class.
Moving between Scenes
| Method | What it does | |
|---|---|---|
start(key, data) | Stops this Scene and starts key. With no key, restarts this Scene | |
restart(data) | Stops this Scene and starts it again | |
launch(key, data) | Starts key alongside this Scene | |
run(key, data) | Wakes key if it's asleep, resumes it if it's paused, otherwise starts it | |
pause(key, data), resume(key, data) | A paused Scene doesn't update, and takes no input, but it still renders | |
sleep(key, data), wake(key, data) | A sleeping Scene doesn't update or render, and keeps its state | |
switch(key, data) | Sleeps this Scene. Wakes key if it's asleep, otherwise starts it | |
stop(key, data) | Shuts key down. Its Game Objects are destroyed |
- Each
keydefaults to this Scene. These methods are queued, and run at the start of the next game step, so the other Scene isn't running on the next line. - Starting a Scene which is already running, paused or asleep restarts it. That includes
launchorrunon a running Scene, andswitchto a paused Scene. Checkthis.scene.isActive(key)first if the Scene may already be running. - These run at once:
get,getStatus,isActive,isPaused,isSleeping,isVisible,setActive,setVisibleandtransition. - The render-order methods, and
addandremove, run at once, or at the next step if called while the Scenes are updating:bringToTop,sendToBack,moveUp,moveDown,moveAbove(keyA, keyB),moveBelow(keyA, keyB),swapPosition. this.scene.add(key, SceneClass, autoStart, data)adds a Scene at run time.remove(key)destroys it.
Passing data
start,restart,launchandrunpassdatatoinit(data)andcreate(data).this.sys.getData()returns it later.restart()with no data, orstart(key)with none, reuses the data from the last start. Pass{}to clear it.- Data given to
pause,resume,sleep,wake, and to aswitchorrunwhich wakes or resumes a Scene, reaches only that event's listeners, as(sys, data).initandcreatedon't run again.
- For state which many Scenes share, use
this.registry(one for the game).this.databelongs to the Scene, and keeps its values across a restart until you callthis.data.reset(). See data-manager.
Running Scenes together
- Scenes render in the order of the game config's
scenearray, so later ones are drawn on top. The top Scene updates first, and gets input first. - A HUD is a second Scene, listed after the game Scene in the config (or moved with
bringToTop), and launched by it. It has its own Camera, so it doesn't scroll or zoom with the game. - To pause the game under a menu:
this.scene.pause()thenthis.scene.launch('Pause'). The paused Scene takes no input, so the Pause Scene must handle the resume:this.scene.resume('Level')thenthis.scene.stop().
One Scene listening to another must remove its listener when it shuts down, because the other Scene's emitter outlives it:
The registry works the same way. Its change event for one key is Phaser.Data.Events.CHANGE_DATA_KEY + 'score', with (parent, value, previousValue), on this.registry.events. Remove it on SHUTDOWN too.
Cleaning up
A Scene instance is kept when it stops, and reused when it starts again. Shutdown destroys its Game Objects, tweens, timers, physics world, Key objects and this.input listeners. It doesn't remove:
- listeners on
this.events, the Scene's own emitter, which lives as long as the Scene. One added increateis added again on every restart; - listeners on anything global:
this.registry,this.scale,this.game.events,this.sound,this.textures, or another Scene'sevents; - sounds made with
this.sound.add, which belong to the game; - key captures, which are global. See input-keyboard-mouse-touch.
Remove these on SHUTDOWN, which runs on every stop and restart. DESTROY runs only when the Scene is removed from the game.
Transitions
transition() runs both Scenes for duration ms, then stops (or sleeps) this one. It draws nothing itself: fade the Cameras yourself.
- It returns
false, and does nothing, if the target doesn't exist, is already running, or either Scene is already transitioning. - Keys:
target,duration(1000),sleep(false: stop this Scene at the end),remove,allowInput(false),moveAbove,moveBelow,data,onUpdate(progress),onStart. - Events:
TRANSITION_OUT (targetScene, duration)on this Scene. On the target:TRANSITION_INIT(afterinit), thenTRANSITION_START(aftercreate) orTRANSITION_WAKE, each with(fromScene, duration), andTRANSITION_COMPLETE (fromScene)at the end.
Gotchas
- Listeners on
this.eventsadded increatepile up across restarts, as do those on global emitters. Remove them onSHUTDOWN. this.scene.start('X')stops the current Scene. Uselaunchto keep both.launch,runorstarton a running Scene restarts it.- Scene methods are queued until the next step.
- Data given to
wakeorresumeonly reaches the event, notinitorcreate. restart()with no data reuses the old data.- Set up per-run state in
init, not the constructor, which runs once. this.physicsandthis.matterexist only if the game or the Scene config sets up that physics.- Never overwrite
this.sys.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/scenes/SKILL.md
Popularity
- Repository stars
- 39,633
- Repository forks
- 7,130
- 7-day trend score
- 53
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 17 May 2026, 6 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Grok Build (Cursor)
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/phaserjs/phaser/scenes)