events-system

Coordinate Phaser 4 game logic with EventEmitter and scene events.

Updated Jun 21, 2021
One-click install
npx skills add https://github.com/mahirocoko/mahirocoko --skill events-system-mahirocoko
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: events-system
Source: https://github.com/mahirocoko/mahirocoko/tree/main/plugins/phaser/skills/events-system
Command: npx skills add https://github.com/mahirocoko/mahirocoko --skill events-system-mahirocoko

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Phaser 4's EventEmitter pattern and built-in scene/game events can be difficult to coordinate; this skill provides a guided approach to using event listeners and emitters to enable decoupled, event-driven communication across scenes and game objects.

Core Features & Use Cases

  • EventEmitter base usage, including on/once/off and lifecycle management.
  • Scene-level events (update/shutdown) and game-level events (blur/resume) for inter-scene coordination.
  • Custom events to propagate game state changes across systems.
  • Practical workflows for managing listeners to prevent memory leaks and clean up on scene shutdown.

Quick Start

Set up a listener for a scene update and emit a custom event to notify other systems when a key game state changes.

Frequently Asked Questions about events-system

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

FAQPage Schema
How do I coordinate Phaser 4 scene events for inter-scene communication?

Coordinate Phaser 4 scene events by using the built-in EventEmitter to listen for scene lifecycle updates and emit custom triggers across systems. This decoupled pattern enables responsive game state communication between active scenes without direct object references.

What is the best way to manage Phaser 4 EventEmitter listeners during scene lifecycle?

Manage Phaser 4 EventEmitter listeners by properly unregistering them during scene shutdown events. Removing listeners on shutdown prevents dangling references and ensures deterministic behavior, which is critical for avoiding memory leaks when transitioning between game scenes.

Why does my Phaser 4 game have memory leaks when switching scenes?

Memory leaks in Phaser 4 scene switching often occur when EventEmitter listeners are not removed during shutdown. Properly calling off to clean up custom event listeners and scene update subscriptions ensures garbage collection prevents persistent memory leaks.

Can I use custom Phaser 4 events to propagate game state changes across modular components?

Use custom Phaser 4 events to propagate game state changes across modular components by emitting triggers through this.events. This event-driven architecture allows decoupled game objects to react to user input and state modifications without tight system coupling.

Does Phaser 4 support game-level events for window blur and resume states?

Phaser 4 supports game-level events like blur and resume through this.game.events for global game state management. These built-in emitters help coordinate pausing and resuming game logic when the browser window loses focus or regains active state.

How to clean up Phaser 4 event listeners to avoid memory leaks on scene shutdown?

Clean up Phaser 4 event listeners by calling off during the scene shutdown event lifecycle phase. Proper listener removal from this.events and this.game.events ensures deterministic behavior and prevents memory leaks when destroying or transitioning game scenes.