events-system

Standardize EventEmitter-based communication in Phaser 4 with lifecycle-safe listener cleanup.

1|Updated May 3, 2026
One-click install
npx skills add https://github.com/WanderTheWeeb/papas_trauma --skill events-system-wandertheweeb
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: events-system
Source: https://github.com/WanderTheWeeb/papas_trauma/tree/main/skills/events-system
Command: npx skills add https://github.com/WanderTheWeeb/papas_trauma --skill events-system-wandertheweeb

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It prevents brittle, error-prone gameplay flow by showing how to correctly listen to, emit, and clean up Phaser 4 events across Game, Scene, Input, Loader, Tweens, Physics, and more.

Core Features & Use Cases

  • EventEmitter-driven communication: Use on, once, off, emit, and removeAllListeners to build decoupled, event-driven gameplay.
  • Lifecycle-safe listener management: Clean up scene listeners on SHUTDOWN to avoid duplicate handlers and memory leaks on scene restart.
  • Typed, autocomplete-friendly constants: Prefer Phaser event constants (e.g., Phaser.Scenes.Events.UPDATE, Phaser.Input.Events.POINTER_DOWN) over raw strings to reduce typos.
  • Multi-scope event routing: Handle scene events via this.events, game-wide events via this.game.events, and emitter-specific events like this.input, this.load, this.anims, and this.physics.world.

Quick Start

Use the events-system skill to wire a pointer-down handler and a scene-shutdown cleanup so you safely emit and respond to custom events like player-died.

Frequently Asked Questions about events-system

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

FAQPage Schema
Why are my Phaser event listeners firing multiple times after restarting a scene?

Phaser event listeners fire multiple times when scene restarts duplicate registered handlers. Remove listeners on the SHUTDOWN event using off() with exact handler references to prevent memory leaks and duplicate callbacks.

How do I use EventEmitter to handle input and pointer interactions in Phaser 4?

Use Phaser.Input.Events constants like POINTER_DOWN with the scene's input emitter (this.input.on()) to handle pointer interactions. Typed constants prevent typos compared to raw strings, ensuring reliable event-driven communication for gameplay logic.

What is the best way to emit custom cross-scene events in a Phaser game?

Emit custom cross-scene events using the game-wide emitter (this.game.events.emit()). Scenes listen via this.game.events.on() with matching event names, establishing decoupled communication while requiring SHUTDOWN cleanup to avoid lingering listeners.

Does Phaser 4 support typed event constants for animations and physics collisions?

Yes, Phaser 4 supports typed event constants for animations (this.anims) and physics collisions (this.physics.world). Using Phaser constants instead of raw strings provides autocomplete-friendly references and reduces typos in event-driven gameplay code.

How do I properly remove a specific event listener in Phaser using off()?

To remove an event listener in Phaser, call off() with the exact event name and the identical handler function reference originally passed to on(). Passing a different or anonymous function reference fails to remove the listener, causing memory leaks.

When should I use once instead of on for Phaser scene lifecycle events?

Use once() for Phaser scene lifecycle events that should only trigger a single time, like loader completion or specific tween finishes. The once() method automatically removes the listener after firing, whereas on() persists until manually cleaned up.