events-system

Implements event-driven communication in Phaser 4 using EventEmitter, scene events, and named constants.

Updated May 7, 2021
One-click install
npx skills add https://github.com/travispwingo/travispwingo.github.io --skill events-system-travispwingo
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: events-system
Source: https://github.com/travispwingo/travispwingo.github.io/tree/main/mario/docs/skills/events-system
Command: npx skills add https://github.com/travispwingo/travispwingo.github.io --skill events-system-travispwingo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Phaser 4 games rely on the EventEmitter pattern across every major system, but remembering event names, emitter scopes, and listener cleanup rules is error-prone and causes memory leaks. This Skill provides a complete reference for wiring up events correctly across scenes, input, loaders, tweens, physics, and more. ## Core Features & Use Cases - Complete Event Reference: Covers all event namespaces including Scene, Game, Input, Loader, Animation, Camera, Sound, Tween, Physics, Texture, GameObject, and Time events with their string values and constants. - Listener Lifecycle Management: Documents on/once/off/emit patterns, context binding, and shutdown cleanup to prevent duplicate listeners on scene restarts. - Inter-Scene Communication: Shows three methods for cross-scene messaging using game.events, the registry DataManager, and direct scene access. - Use Case: When building a HUD that must react to score changes in a gameplay scene, use this Skill to set up a game.events listener with proper SHUTDOWN cleanup so the HUD never accumulates stale listeners. ## Quick Start Ask the AI to show how to listen for a pointerdown event in a Phaser scene and clean it up when the scene shuts down.

Frequently Asked Questions about events-system

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I listen for events in a Phaser scene?▼

Use this.events.on() with a named constant like Phaser.Scenes.Events.UPDATE, passing the handler and context. For one-time events use once(), and emit custom events with this.events.emit('event-name', data).

How to communicate between scenes in Phaser?▼

Use this.game.events as a global event bus, the shared this.registry DataManager with changedata events, or direct scene access via this.scene.get('SceneKey').events. Each method works across all running scenes.

Why do Phaser event listeners duplicate after scene restart?▼

Listeners registered with on() persist when a scene restarts because shutdown does not auto-remove them. Clean up by calling off() inside a SHUTDOWN handler, or use once() for single-fire listeners.

Should I use event string names or constants in Phaser?▼

Prefer named constants like Phaser.Input.Events.POINTER_DOWN over raw strings like 'pointerdown'. Constants prevent typos, enable IDE autocomplete, and map predictably to their lowercase string values.

Why does off() not remove my Phaser event listener?▼

off() only works when you pass the exact same function reference and context used with on(). Anonymous or inline arrow functions cannot be removed, so store a named method reference instead.