scenes
Use this skill when working with Phaser 4 scenes. Covers scene lifecycle methods, scene transitions, parallel scenes, scene communication, sleeping, pausing, restarting, and the SceneManager. Triggers on: Scene, scene lifecycle, preload, create, update, scene transition, SceneManager.
What this skill does
# Scenes
> Scenes are the organizational backbone of a Phaser game. Each Scene has its own lifecycle (init, preload, create, update), its own set of injected systems (this.add, this.input, this.cameras, etc.), and can be started, stopped, paused, slept, or run in parallel with other Scenes. The ScenePlugin (`this.scene`) controls all multi-scene orchestration.
**Key source paths:** `src/scene/Scene.js`, `src/scene/Systems.js`, `src/scene/SceneManager.js`, `src/scene/ScenePlugin.js`, `src/scene/Settings.js`, `src/scene/const.js`, `src/scene/events/`, `src/scene/InjectionMap.js`
**Related skills:** ../game-setup-and-config/SKILL.md, ../loading-assets/SKILL.md, ../events-system/SKILL.md
## Quick Start
```js
// Minimal scene with all lifecycle methods
class GameScene extends Phaser.Scene {
constructor() {
super('GameScene');
}
init(data) {
// Called first. Receives data passed from other scenes.
// 'data' is whatever was passed via scene.start('GameScene', { level: 1 })
this.level = data.level || 1;
}
preload() {
// Called after init. Load assets here.
this.load.image('logo', 'assets/logo.png');
}
create(data) {
// Called after preload completes. Set up game objects.
// 'data' is the same object passed to init.
this.add.image(400, 300, 'logo');
}
update(time, delta) {
// Called every frame while scene is RUNNING.
// time: current time (ms), delta: ms since last frame (smoothed)
}
}
const config = {
width: 800,
height: 600,
scene: [GameScene]
};
const game = new Phaser.Game(config);
```
## Core Concepts
### Scene Lifecycle
The lifecycle is driven by `SceneManager.bootScene()` and `SceneManager.create()`:
1. **PENDING (0)** - Scene is registered but not yet started.
2. **INIT (1)** - `scene.init(data)` is called if defined. Data comes from `settings.data`.
3. **START (2)** - `Systems.start()` fires. Events `start` and `ready` are emitted.
4. **LOADING (3)** - `scene.preload()` is called if defined. Loader runs. On completion, proceeds to create.
5. **CREATING (4)** - `scene.create(data)` is called if defined. Same `data` as init.
6. **RUNNING (5)** - `scene.update(time, delta)` called every frame. Scene renders.
7. **PAUSED (6)** - No update, but still renders.
8. **SLEEPING (7)** - No update, no render. State preserved in memory.
9. **SHUTDOWN (8)** - Scene is shut down, systems emit `shutdown`. Can be restarted.
10. **DESTROYED (9)** - Scene is fully destroyed. Cannot be restarted.
State constants are on `Phaser.Scenes`: `Phaser.Scenes.PENDING`, `Phaser.Scenes.RUNNING`, etc.
**Flow when no preload exists:** `init()` -> `create()` -> `update()` loop (preload is skipped entirely).
**Flow with preload:** `init()` -> `preload()` -> loader runs -> `create()` -> `update()` loop.
### Scene-Injected Properties
These properties are injected into every Scene instance via the InjectionMap (`src/scene/InjectionMap.js`). The left side is the Systems key, the right is the Scene property name.
#### Global Managers (shared across all scenes)
| Scene Property | Type | Description |
|---|---|---|
| `this.game` | `Phaser.Game` | The Game instance |
| `this.renderer` | `CanvasRenderer \| WebGLRenderer` | The active renderer |
| `this.anims` | `Phaser.Animations.AnimationManager` | Global animation manager |
| `this.cache` | `Phaser.Cache.CacheManager` | Global cache for non-image assets |
| `this.plugins` | `Phaser.Plugins.PluginManager` | Global plugin manager |
| `this.registry` | `Phaser.Data.DataManager` | Global data manager (shared between scenes) |
| `this.scale` | `Phaser.Scale.ScaleManager` | Global scale manager |
| `this.sound` | `NoAudio \| HTML5Audio \| WebAudioSoundManager` | Sound manager |
| `this.textures` | `Phaser.Textures.TextureManager` | Global texture manager |
#### Scene-Specific Systems (unique per scene)
| Scene Property | Type | Description |
|---|---|---|
| `this.sys` | `Phaser.Scenes.Systems` | Scene systems (never overwrite) |
| `this.events` | `Phaser.Events.EventEmitter` | Scene-specific event emitter |
| `this.cameras` | `Phaser.Cameras.Scene2D.CameraManager` | Scene camera manager |
| `this.add` | `Phaser.GameObjects.GameObjectFactory` | Factory: creates and adds to display list |
| `this.make` | `Phaser.GameObjects.GameObjectCreator` | Creator: creates but does NOT add to display list |
| `this.scene` | `Phaser.Scenes.ScenePlugin` | Scene manager plugin (start/stop/launch) |
| `this.children` | `Phaser.GameObjects.DisplayList` | The scene display list |
| `this.lights` | `Phaser.GameObjects.LightsManager` | Scene lights (plugin) |
| `this.data` | `Phaser.Data.DataManager` | Scene-specific data manager |
| `this.input` | `Phaser.Input.InputPlugin` | Scene input manager (plugin) |
| `this.load` | `Phaser.Loader.LoaderPlugin` | Scene loader (plugin) |
| `this.time` | `Phaser.Time.Clock` | Scene time/clock (plugin) |
| `this.tweens` | `Phaser.Tweens.TweenManager` | Scene tween manager (plugin) |
| `this.physics` | `Phaser.Physics.Arcade.ArcadePhysics` | Arcade physics (if configured) |
| `this.matter` | `Phaser.Physics.Matter.MatterPhysics` | Matter physics (if configured) |
#### Customizing the Injection Map
```js
// Rename injected properties via scene config
const config = {
key: 'MyScene',
map: {
add: 'makeStuff', // this.makeStuff instead of this.add
load: 'loader' // this.loader instead of this.load
}
};
```
### Scene Manager
The `SceneManager` (`src/scene/SceneManager.js`) is a game-level system. Do not call its methods directly -- use `this.scene` (the ScenePlugin) instead. The SceneManager:
- Maintains an ordered array of scenes (determines render/update order)
- Processes a queue of operations (start, stop, sleep, etc.) at the start of each game step
- All ScenePlugin methods are queued, not immediate (they execute next frame)
## Common Patterns
### Switching Between Scenes
```js
// start() -- shuts down current scene, starts target scene
// Current scene gets SHUTDOWN event; target gets full lifecycle
this.scene.start('LevelTwo', { score: 100 });
// restart() -- shuts down and restarts the same scene
this.scene.restart({ score: 0 });
// switch() -- sleeps current scene, starts/wakes target scene
// Current scene state is preserved in memory
this.scene.switch('PauseMenu', { fromScene: 'GameScene' });
// transition() -- animated transition with duration
this.scene.transition({
target: 'LevelTwo',
duration: 1000,
moveAbove: true, // render target above this scene
sleep: false, // false = stop this scene (default), true = sleep it
remove: false, // true = remove this scene from manager after transition
allowInput: false, // allow input on this scene during transition
data: { score: 100 },
onUpdate: function (progress) {
// progress: 0 to 1 over duration
}
});
```
### Running Scenes in Parallel
```js
// launch() -- starts another scene in parallel (does NOT stop current scene)
this.scene.launch('UIScene', { lives: 3 });
// run() -- smart launcher: starts if not running, resumes if paused, wakes if sleeping
this.scene.run('UIScene', { lives: 3 });
// Control render order of parallel scenes
this.scene.bringToTop('UIScene'); // render last (on top)
this.scene.sendToBack('Background'); // render first (behind)
this.scene.moveAbove('GameScene', 'UIScene'); // UIScene renders above GameScene
this.scene.moveBelow('GameScene', 'Background');
this.scene.moveUp('UIScene'); // move one position up
this.scene.moveDown('UIScene'); // move one position down
this.scene.swapPosition('SceneA', 'SceneB');
```
### Passing Data Between Scenes
```js
// Method 1: Pass data via start/launch/restart/switch/wake/run
this.scene.start('LevelScene', { level: 5, score: 1200 });
// In LevelScene:
// init(data) { data.level === 5 }
// create(data) { data.scRelated in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.