Preloading JSON file before the assets?

Hi!

In this game I am working on I have 10 levels which runs into the same scene class (ScenePlay). So I have different JSON files with configuration data for each level, including different assets to be preloaded. The problem is that it causes an “egg-chicken problem” since the JSON file should be together with the assets in the same preloader() function.

I imagined that one way of turn around this limitation would be to write a preloader scene which only job would be to load the JSON and then send the list of the assets to the ScenePlay init().

Is this a reasonable way of dealing with this situation or there is a better way of doing it?

Thanks!

You can queue more assets when the JSON file loads.

this.load.json('level1');
this.load.on('filecomplete-json-level1', (key, type, data) => {
  this.load.image(data.images);
  this.load.spritesheet(data.spritesheets);
});
1 Like

Ohhhh… this is a great idea I didn’t have think of!

PS: It worked wonderfully! :slight_smile: