Arthur Miksza Posted May 24, 2017 Share Posted May 24, 2017 Hi! I need load some images based on a JSON, I've tried: init() { game.load.json('json_key', 'url_to_json.json'); game.load.start(); } and then: preload() { game.cache.getJSON('json_key').imagesName.forEach((name) => { game.load.image(name, 'url' + name + '.png'); }); } but it's not working... the variable game.cache.getJSON('json_key') is null on preload(), but it has the value on create(); I don't wanna use onLoadComplete() because the generic loading bar that I'm using won't calculate the values after the load has completed. Edit: I know it's possible on create(), but I need it on preload for the loading bar So that's my question, is there any way to do it? Thanks; Link to comment Share on other sites More sharing options...
samme Posted May 25, 2017 Share Posted May 25, 2017 Load JSON in one state, load images in a second state. Link to comment Share on other sites More sharing options...
Contra Code Posted May 26, 2017 Share Posted May 26, 2017 If you're unfamiliar with States in Phaser, take a look at the following tutorial and take note of the Project Setup and Structure section. Full source code for the tutorial is available at the end. https://gamedevelopment.tutsplus.com/tutorials/getting-started-with-phaser-building-monster-wants-candy--cms-21723 Link to comment Share on other sites More sharing options...
Recommended Posts