Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Retrieving JSON from Assetloader or Things loading out of order.


Background_nose
 Share

Recommended Posts

Hi,

 

I'm having trouble getting to the JSON data exported from a tile based map editing program I would like to use. I would like to know how to access the JSON data that is loaded by asset loader, as this loads the JSON for use as a texture atlas. However the same JSON contains an array with which tiles should go where. I would like to read this but I can't work out how.

 

If I try to load the same JSON again with the PIXI.JsonLoader class it seems to load out of order, not finishing until after the first main update is called causing bad things to happen as the level isn't loaded yet.

 

Is there a way to access the extra JSON data (beyond just creating a SpriteSheet)?

 

Is there a way to delay continuing untill all things have loaded?

 

My project (as it stands) is a mess but resides here: https://dl.dropboxusercontent.com/u/118389529/Site/index.html in non-working form. The relevent bits are:

 

Turning the array contained in JSON to a grid of tiles: https://dl.dropboxusercontent.com/u/118389529/Site/level.js

 

and the init function in index.html

 

Appologies, the code isn't the most elegant at the moment.

 

Many thanks for any help.

 

 

Link to comment
Share on other sites

  • 1 month later...

I realise this is a little late, but I've stumbled across a vaguely related issue which led me here. This discussion doesnt help me but maybe this info will help you!

 

I also have additional bits of data that I've added to the texture atlas json file, which I use to help set up textures and sprites and stuff on load.

 

TextureAtlas.json snippet:

 

```

"frames": {  "frameID": {    "frame": {      "x": 0,      "y": 0,      "w": 0,      "h": 0    },    "offset": {      "x": 0,      "y": 0    },    ...more data...

```

 

So, in my case, the offset object is additional.

 

Loader snippet:

 

```
var loader = new PIXI.JsonLoader( filename );loader.on( 'loaded', function( event ) {  _.each( event.content.json.frames, function( frame, frameName ) {    // do stuff in here        // additional props can be accessed in here e.g.    doSomething( frame.offset.x, frame.offset.y );  });});loader.on( 'error', errorHandler );loader.load();
```
 
The only additional complexity here is the `each` function, if you're familiar with lodash or underscore then you'll know that all this function does is loop over each property in the object and call the callback with the value and key that represent that prop. So, in this case, all I'm doing is iterating over the `frames` object and accessing each of my `frame` objects and then doing stuff.
 
Of course, if your additional data is just in the main json file (i.e. not in each frame like this example) then it'll be accessible on the event.content.json object which is a raw object parsed from the json in your texture atlas file.
Link to comment
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...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...