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
registrysends events through the game'sevents. Theparentargument is the game. - The scene
datasends events through the scene'sevents. Theparentargument is the scene. - A game object's
datasends events through the game object itself. Theparentargument 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.