phaserjs/phaser/events-system
Claude Code and agent skill by phaserjs/phaser
- community
Checking that the SKILL.md file is still in the repository.
Phaser 4 events: EventEmitter (on, once, off, emit, context), which object emits which events, the event constants (Phaser.Scenes.Events, Phaser.Core.Events, Phaser.Input.Events, Phaser.Loader.Events and the rest) and where each set lives in src, per-key events such as keydown-SPACE and filecomplete-image-key, custom events and an event bus between Scenes, and removing listeners on SHUTDOWN. Use when wiring a HUD to the game Scene, pausing on blur or a hidden tab, reacting to resize, game over, or a listener firing twice after scene.restart(). Corrects v3 habits and common bugs: listeners on this.events, this.game.events, this.registry, this.scale and other Scenes leak across restarts; a mistyped event string never fires; removeAllListeners on this.events breaks the Scene. Triggers on: events, on, once, off, emit, EventEmitter, listener, event bus, SHUTDOWN, cleanup, memory leak, custom event.
Install
npx vskill@latest install phaserjs/phaser/events-systemSKILL.md
The same SKILL.md was published earlier as phaserjs/phaser/events-system.
Events
Phaser's systems are event emitters, built on eventemitter3. This covers how to listen, which object emits what, where the event constants live, and how to remove listeners so a Scene restart doesn't duplicate them.
Source: src/events/EventEmitter.js, and the events/ folder of each system (table below). Related: phaser4-core, scenes, data-manager, input-keyboard-mouse-touch.
Quick start
The EventEmitter
Phaser.Events.EventEmitter is eventemitter3 with shutdown() and destroy() added, both of which call removeAllListeners().
on(event, fn, context?)andonce(...)return the emitter, so they chain.addListenerison.off(event, fn?, context?, once?)(alsoremoveListener): withfnit removes only that function, and withcontextonly for that context. Without `fn` it removes every listener for the event, including ones other Scenes added.emit(event, ...args)returnstrueif anything was listening. Listeners run in the order they were added, synchronously.listenerCount(event),listeners(event),eventNames(),removeAllListeners(event?).- The third argument sets
thisin a normal function. An arrow function keeps thethisof where it was written and ignores it. offneeds the same function to find a listener. An inline arrow function can't be removed later, so use a method, or keep the function in a variable.- A Game Object is an emitter, so
sprite.on('pointerdown', ...)andsprite.emit('hit')work. Its listeners go when it is destroyed.
Which object emits what
Every built-in event has a constant whose value is the string, such as Phaser.Input.Events.POINTER_DOWN === 'pointerdown'. The constants, with the arguments each event passes, are one file per event in these folders:
| Constants | Folder in src/ | Emitted by | Cleared when the Scene shuts down? | |
|---|---|---|---|---|
Phaser.Scenes.Events | scene/events/ | this.events | No, kept across restarts | |
Phaser.Core.Events | core/events/ | this.game.events | No | |
Phaser.Input.Events | input/events/ | this.input, and interactive Game Objects | Yes | |
this.input.manager.events (POINTERLOCK_CHANGE, MANAGER_*) | No | |||
Phaser.Input.Keyboard.Events | input/keyboard/events/ | this.input.keyboard, and each Key | Yes | |
Phaser.Input.Gamepad.Events | input/gamepad/events/ | this.input.gamepad, and each Gamepad | Yes | |
Phaser.Loader.Events | loader/events/ | this.load | Yes | |
Phaser.Cameras.Scene2D.Events | cameras/2d/events/ | each Camera | Yes, the Cameras are destroyed | |
Phaser.GameObjects.Events | gameobjects/events/ | each Game Object, and Video (VIDEO_*) | Yes, they are destroyed | |
Phaser.GameObjects.Particles.Events | gameobjects/particles/events/ | each ParticleEmitter | Yes | |
Phaser.Animations.Events | animations/events/ | this.anims (ADD_ANIMATION, PAUSE_ALL...), and each Sprite (ANIMATION_*) | this.anims: No | |
Phaser.Tweens.Events | tweens/events/ | each Tween | Yes, the Tweens are destroyed | |
Phaser.Time.Events | time/events/ | each Timeline (COMPLETE). A TimerEvent isn't an emitter: use its callback | Yes, the Timelines are destroyed | |
Phaser.Sound.Events | sound/events/ | this.sound (GLOBAL_*, DECODED, UNLOCKED...), and each Sound | No | |
Phaser.Physics.Arcade.Events | physics/arcade/events/ | this.physics.world | Yes | |
Phaser.Physics.Matter.Events | physics/matter-js/events/ | this.matter.world | Yes | |
Phaser.Data.Events | data/events/ | the owner of the data: a Game Object, this.events (for this.data) or this.registry.events | Game Object: yes. this.events and the registry: No | |
Phaser.Scale.Events | scale/events/ | this.scale | No | |
Phaser.Textures.Events | textures/events/ | this.textures | No | |
Phaser.Cache.Events | cache/events/ | each cache's events, such as this.cache.json.events | No | |
Phaser.Renderer.Events | renderer/events/ | this.renderer | No | |
Phaser.Structs.Events | structs/events/ | a ProcessQueue (internal) |
The same string is used by several systems: 'complete', 'start', 'update', 'pause', 'destroy', 'add'. Listening on the wrong emitter does nothing and reports nothing, which is one more reason to use the constants: Phaser.Tweens.Events.TWEEN_COMPLETE makes it clear the listener belongs on a Tween.
Since 4.3 the constants have literal types in TypeScript, such as 'pointerdown' rather than string.
Scene and Game events
Each frame a Scene emits PRE_UPDATE, UPDATE, then calls its update(time, delta), then POST_UPDATE. When it renders it emits PRE_RENDER and then RENDER, after its Cameras have drawn. The lifecycle events are BOOT (once), START, READY, CREATE, PAUSE, RESUME, SLEEP, WAKE, SHUTDOWN, DESTROY and the TRANSITION_* events. See scenes.
this.game.events emits BLUR and FOCUS (the window), HIDDEN and VISIBLE (the tab), PAUSE and RESUME (the game loop), PRE_STEP, STEP, POST_STEP, PRE_RENDER, POST_RENDER, CONTEXT_LOST, READY, BOOT and DESTROY.
Per-key events
Some events have a prefix constant, and the event is the prefix plus a name:
The others are Phaser.Input.Keyboard.Events.KEY_UP, Phaser.Textures.Events.ADD_KEY and REMOVE_KEY ('addtexture-<key>'), and Phaser.Data.Events.CHANGE_DATA_KEY ('changedata-<key>'). The name keeps its case. Key names are the upper case Phaser.Input.Keyboard.KeyCodes names, such as 'A', 'SPACE' and 'LEFT'.
Removing listeners on SHUTDOWN
A Scene stops or restarts with SHUTDOWN, and only fires DESTROY when it is removed from the game. What is cleared on shutdown is in the table above. Everything marked No keeps its listeners, and create adds them again on the next start, so the handler runs twice, then three times, and keeps the old Scene alive.
- Never call
this.events.removeAllListeners(), oroff(event)without a function, on a Scene. The Scene's own systems, such as the Clock, Tweens, Cameras and the update list, listen onthis.events, and the Scene stops working.
Custom events and an event bus
For events inside one Scene, emit on this.events with your own names. For events between Scenes, use one shared emitter:
this.game.events works as a bus too, but its names can clash with Phaser's own game events, such as 'pause'. For values rather than one-off events, the registry is often simpler: see data-manager.
Gotchas
- Arcade Physics `COLLIDE`, `OVERLAP`, `TILE_COLLIDE`, `TILE_OVERLAP` and `WORLD_BOUNDS` only fire for bodies which ask for them: set
body.onCollide,body.onOverlaporbody.onWorldBoundstotrue. Colliders also take a callback. - `POINTERLOCK_CHANGE` is emitted on `this.input.manager.events`, not
this.input. - Sound Manager events are `GLOBAL_MUTE` (`'mute'`), `GLOBAL_VOLUME` (`'volume'`) and so on, on
this.sound.DECODEDandDECODED_ALLare emitted by the Sound Manager, not a Sound. - The Animation Manager emits `ADD_ANIMATION` as `'add'`, not
'addanimation'. - `Phaser.Time.Events.COMPLETE` is for a Timeline. Since 4.3 it waits until the Tweens the Timeline started have finished.
- New in 4.3:
Phaser.Loader.Events.FILE_LOAD_RETRY('loadretry', withfile, event, retries), and the Scale Manager now emitsPhaser.Scale.Events.FULLSCREEN_FAILEDwhen the browser refuses fullscreen. - An error thrown in a listener stops the listeners after it for that emit, and propagates to the code which called
emit.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/events-system/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/events-system)