Cache add events

Hello there,

I am using the phaser3-webpack-project-template(which is great) but had a couple quick questions:

  1. Since I specify imports for all my webpack data files, there seems to be no need for using the loader, instead I should just add those files directly to the global cache, is this correct?

  2. I am successfully adding a json file to the cache however I cannot for the life of me seem to catch the add event. Any pointers would be appreciated I have put the relevant snippet below.

    import levelData from ‘…/data/levels.json’;

    preload() {
    let loadFileText = this.add.text(300, 300, ‘’);
    this.events.on(Phaser.Cache.Events.ADD, function (cache, key, obj) {
    console.log(“Got add event”, key);
    loadFileText.setText('Loaded file ’ + key);
    });
    this.cache.json.add(‘levelData’, levelData);
    }

PS sorry for the formatting, I’m not finding a way to properly embed a code block

this.cache.json.events.on(Phaser.Cache.Events.ADD, console.log);

etc.

You can paste code between triple backticks.

```
import levelData from ‘…/data/levels.json’;
```
1 Like

Thanks! I thought I had tried that but it is working now so obviously not. Thanks for the tip on the backticks as well.