Son of Bryce Posted September 6, 2013 Share Posted September 6, 2013 Hello ya'll, I've got a basic question but I wanted to get opinions of the easiest way to load a JSON file and access it immediately after. I based this on one of the examples:var assetsToLoader = ["assets/GameData.json"];loader = new PIXI.AssetLoader(assetsToLoader);// create a new loaderloader.onComplete = onJsonLoaded; // use callbackloader.load(); //begin load My problem is I didn't understand how I'm supposed access the JSON object after it's loaded. Is the object passed into onJsonLoaded or is there a method within AssetLoader to access it. And would that work for multiple files as well? Thanks! Quote Link to comment Share on other sites More sharing options...
Qqwy Posted September 6, 2013 Share Posted September 6, 2013 I went through the source of PIXI, and to my understanding the JSON code gets passed as a property of the this object that is sent to the callback. You should be able to access it using this.json . At least that's what I think right now. But it might also an illusion coming from sleep-deprivation. Quote Link to comment Share on other sites More sharing options...
Son of Bryce Posted September 6, 2013 Author Share Posted September 6, 2013 Thanks for the reply. It seems like "this.json" isn't working. From what I can tell the only properties it has are "assetURLs", "loadCount", "loadersByType" ( which has a "json" object but doesnt appear to have any data). I'm trying to figure it out by debugging with FireBug. I found some examples of using the JsonLoader object somewhere in the source. I may just try that. I thought it would be a lot easier if I could bulk load everything at once with the AssetLoader and access the objects from that. Which is what it seemed to be for. Quote Link to comment Share on other sites More sharing options...
xerver Posted September 7, 2013 Share Posted September 7, 2013 That is exactly what it is for, but the json loader was really intended to load sprite sheets and spine data into the pixi cache. You can load and use json data by creating a JSON loader explicitly and using that, unfortunately that is the only way to load arbitrary json right now. We are in the processes of a large pixi release which will revamp a lot of these "extra" modules so hang in there. For now, loading json can be done like:var loader = new PIXI.JsonLoader(url);loader.on('loaded', function(evt) { //data is in evt.content.json evt.content.json});loader.load(); Quote Link to comment Share on other sites More sharing options...
Son of Bryce Posted September 7, 2013 Author Share Posted September 7, 2013 Awesome, thanks for the help guys! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.