Vaughan Posted April 18, 2014 Share Posted April 18, 2014 I see that there's a jsonLoadComplete callback but it returns an index and there's no real documentation or examples on how to do this. For example, I have a JSON with all the sprites I want to load up front -- how can I load this JSON, and then proceed to iterate that object to load the rest? Link to comment Share on other sites More sharing options...
bmceldowney Posted April 18, 2014 Share Posted April 18, 2014 My understanding is that you can load the json like this:game.load.json('myKey', 'path/to/json/file.json');Then when you want to retrieve the json you grab it from the cache:game.cache.getJSON('myKey'); Link to comment Share on other sites More sharing options...
Vaughan Posted April 18, 2014 Author Share Posted April 18, 2014 That's right -- but I need to load sprites based on that JSON result. I'm doing this within preload, so I can't just do a getJSON right, can I? It was my understanding that these calls are async. Link to comment Share on other sites More sharing options...
bmceldowney Posted April 18, 2014 Share Posted April 18, 2014 I guess you'd call getJSON in an game.load.onLoadComplete handler? There may well be a better way to do it but it seems like that would work. Link to comment Share on other sites More sharing options...
Vaughan Posted April 18, 2014 Author Share Posted April 18, 2014 Isn't the loader inactive then? I need to load textures based on this JSON file. I was under the impression when preload ends that phasers loader becomes inactive. Link to comment Share on other sites More sharing options...
sleekdigital Posted April 19, 2014 Share Posted April 19, 2014 One way is to use multiple states for your preloading. In your first state's preload function, load the JSON and any other assets you already know you need. Then in the next state's preload function, read the json and load the textures. Then in create function of that state you are all set to render. http://docs.phaser.io/Phaser.StateManager.html Link to comment Share on other sites More sharing options...
Vaughan Posted April 19, 2014 Author Share Posted April 19, 2014 That's actually a good idea, sleekdigital. Not sure why I didn't think of that. Link to comment Share on other sites More sharing options...
bmceldowney Posted April 19, 2014 Share Posted April 19, 2014 Isn't the loader inactive then? I need to load textures based on this JSON file. I was under the impression when preload ends that phasers loader becomes inactive. I would assume that the callback you add to onLoadComplete would get called once the load process completes, so if you add the callback in the preload function then it will get called. Edit: I see missed your point. Go with sleekdigital's suggestion. Link to comment Share on other sites More sharing options...
Vaughan Posted April 19, 2014 Author Share Posted April 19, 2014 I did this and it worked out fine -- I loaded the pack up during the bootstrap phase and then loaded the actual sprites themselves on the gameplay screen. Link to comment Share on other sites More sharing options...
Recommended Posts