Background_nose Posted February 25, 2014 Share Posted February 25, 2014 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. Quote Link to comment Share on other sites More sharing options...
Background_nose Posted February 25, 2014 Author Share Posted February 25, 2014 . Quote Link to comment Share on other sites More sharing options...
mattstyles Posted April 5, 2014 Share Posted April 5, 2014 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. Quote Link to comment Share on other sites More sharing options...
xerver Posted April 7, 2014 Share Posted April 7, 2014 var loader = new PIXI.AssetLoader(['my/json/file/path.json']); loader.on('onProgress', function(evt) { if(evt.loader.json) console.log(evt.loader.json); }); loader.load(); 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.