What problem does it solve?
It helps you manage and synchronize custom game state by storing key-value data on game objects, scenes, and the global registry while reacting to changes through events instead of tightly coupling systems.
Core Features & Use Cases
- Per-GameObject data: Use Phaser DataManager via sprite.setData/getData/incData/toggleData to attach state directly to entities and listen to events like changedata-hp.
- Scene-level data: Use this.data as a DataManagerPlugin for scene-specific state that integrates with the scene event bus.
- Global registry state: Use game.registry (this.registry in scenes) for cross-scene values that persist for the lifetime of the Game.
- Event-driven updates: React to setdata, changedata, changedata-{key}, and removedata with the correct callback signatures depending on where the DataManager lives.
- Practical use case: Keep a score in the GameScene and have a HUD scene automatically update its UI by listening to registry changedata-score events, while ensuring listeners are removed on shutdown to avoid stale updates.
Quick Start
Use the data-manager skill to set and update a sprite’s hp with sprite.setData('hp', 100) and then listen for sprite.on('changedata-hp', ...) to drive health UI and destruction logic.