Data - samme/phaser3-faq GitHub Wiki
The DataManager component is in
You can also create one for your own purposes:
const playerInventory = { data: null, events: new Phaser.Events.EventEmitter() };
playerInventory.data = new Phaser.Data.DataManager(playerInventory);
playerInventory.events.on('setdata', console.log);
playerInventory.data.set('gold', 1);
Examples
To JSON and back
const json = JSON.stringify(data.list);
// …
data.reset().merge(JSON.parse(json));
Events
- The game
registry
sends events through the game'sevents
. Theparent
argument is the game. - The scene
data
sends events through the scene'sevents
. Theparent
argument is the scene. - A game object's
data
sends events through the game object itself. Theparent
argument is the game object.
SET_DATA means an entry was created.
CHANGE_DATA means an existing entry was written to, not necessarily changed — but you can detect a change by comparing value
and previousValue
in the callback.