hbkmad Posted June 7, 2015 Share Posted June 7, 2015 Hello, I'm making an AJAX request to a server to know exactly which images I have to load. But the problem is I want first the response to come and then to start loading whatever I need. Is there a way to make that without making the AJAX synchronous itself? Maybe if I make the request and call game.state.start("myscene") when the response have arrived but how would I be able to send the variables I need to this scene without making them global? Link to comment Share on other sites More sharing options...
Carlos Posted June 8, 2015 Share Posted June 8, 2015 The docs say that you can send additional parameters to game.state.start(key, clearWorld, clearCache, parameter). The additional parameters will be sent to your State.init function. https://phaser.io/docs/2.3.0/Phaser.StateManager.html#start Link to comment Share on other sites More sharing options...
Skeptron Posted June 8, 2015 Share Posted June 8, 2015 Or you can make the AJAX request in your loading state, put the loading of the images in the success function(which is fed with server's response, that is, the images to load), and make you loading state switch to game state only when the images are loaded. Link to comment Share on other sites More sharing options...
hbkmad Posted June 9, 2015 Author Share Posted June 9, 2015 Thank you guys. I ended up sending them as parameters. Skeptron, how can I call the "Create" state manually and be sure that is not called automatically before the response have come? Link to comment Share on other sites More sharing options...
Recommended Posts