Data - samme/phaser3-faq GitHub Wiki

The DataManager component is in

  • The game registry
  • Each scene's data
  • A game object's data, after getData() or setData() is called

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's events. The parent argument is the game.
  • The scene data sends events through the scene's events. The parent argument is the scene.
  • A game object's data sends events through the game object itself. The parent 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.