Son of Bryce

Loading multiple JSON files with AssetLoader

Recommended Posts

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!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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();

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.