events-system

Coordinate Phaser 4 event-driven communication across scenes and game systems.

Updated Apr 26, 2026
One-click install
npx skills add https://github.com/kehwar/pixi-square --skill events-system-kehwar
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: events-system
Source: https://github.com/kehwar/pixi-square/tree/main/.agents/skills/events-system
Command: npx skills add https://github.com/kehwar/pixi-square --skill events-system-kehwar

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Phaser relies on the EventEmitter pattern across its systems, which can lead to scattered listeners and hard-to-trace flows. This skill provides guidance for organizing event-driven communication across Game, Scene, and UI layers, ensuring reliable messaging and clean lifecycle management.

Core Features & Use Cases

  • EventEmitter basics (on/once/off, removeAllListeners) and proper cleanup practices
  • Distinguishing scene-level vs game-level events (this.events vs this.game.events) and inter-scene messaging
  • Using named constants (Phaser.*.Events, etc.) to avoid typos and enable IDE autocomplete
  • Handling custom events and inter-system communication with predictable, testable patterns
  • Best practices for listener management to prevent memory leaks during scene restarts

Quick Start

Listen for a scene event and emit a custom event to notify other parts of the game

Frequently Asked Questions about events-system

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

FAQPage Schema
How do I manage Phaser 4 event listeners to prevent memory leaks during scene restarts?

To prevent memory leaks during Phaser scene restarts, use proper listener management by calling off or removeAllListeners to clean up active event emitters before the scene shuts down. This ensures destroyed scenes do not retain references to old callback functions.

What is the difference between scene-level and game-level events in Phaser?

Scene-level events are scoped to the current scene via this.events, while game-level events are globally scoped via this.game.events. Distinguishing them allows you to control inter-scene messaging and broadcast communication across the Game, Scene, and UI layers.

How do I send custom events between scenes in Phaser 4?

You send custom events between Phaser scenes by emitting messages on the shared game-level event emitter. Other scenes listen to this.game.events using the on or once methods to receive the inter-system communication and execute their corresponding logic.

Why should I use named constants for Phaser event strings instead of plain text?

Using named constants like Phaser.*.Events for event strings avoids typos and enables IDE autocomplete. This practice ensures reliable messaging by validating event names at compile time, making your event-driven flows predictable and easier to trace.

Does the Phaser EventEmitter pattern work for inter-system UI communication?

The Phaser EventEmitter pattern works for inter-system UI communication by coordinating event-driven messaging across the Game, Scene, and UI layers. It uses on, once, and off methods to handle input-driven events and custom notifications cleanly.

What is the best way to organize scattered event listeners in a Phaser game?

The best way to organize scattered listeners is grouping event-driven communication by scope using scene-level and game-level emitters. Applying predictable patterns and proper cleanup practices ensures reliable messaging and clean lifecycle management.