mrsnow Posted July 6, 2014 Share Posted July 6, 2014 Hi everyone i need a bit help with this and phaser what is the best way to load a json data from a server with jquery ajax, can i use jquery with phaser? can i use a ajax call like a webapp for example $.ajax({ type: GET,POST ETC, url: somewhere, data:some data, callback function....... }) or exist another way to do this . This is my first time with phaser and i am developing a game with this features: 1) i have a main view with a image logo2) this second view is sign up form (i need send a json to the server) 3) the third view is for instructions and has the start game buttom4) the next view is the first level5) this view is after finish the level in this view we have a question (i need to do a get request to load questions and answers from the server and then send a POST request the answer to the server again) Link to comment Share on other sites More sharing options...
Budda Posted August 16, 2015 Share Posted August 16, 2015 http://phaser.io/examples/v2/loader/load-json-file is probably a start. However it appears http://phaser.io/docs/2.4.2/Phaser.Loader.html#json only does get requests, and no POST back for item 5 in your list. Link to comment Share on other sites More sharing options...
MichaelD Posted August 16, 2015 Share Posted August 16, 2015 Of cource you can add .json file and use jquery for these matters. One neat trick you can do is to declare your json object as a variable.var jsonObj = {};And have this file declared as a .js file which you can load in a script tag.<script type="text/javascript" src="myJSON.js"></script>This way you can load json objects even in sandboxed environments like Codepen or other sites. I used this technique in my example: http://nightlycoding.com/index.php/2015/01/phaser-io-how-to-use-atlashash-to-your-advantage/#more-645 to load the json for the sprite animations. Link to comment Share on other sites More sharing options...
georgejfrick Posted August 16, 2015 Share Posted August 16, 2015 You can add a text resource during preload.// during preload of a stategame.load.text('playData', 'media/play.json'); // give url of your file.// after preloadvar jsonData = JSON.parse(game.cache.getText('playData')); Link to comment Share on other sites More sharing options...
Recommended Posts