NewGuy Posted April 11, 2017 Share Posted April 11, 2017 Hi all, for the record have seen a similar post before but it was quite different to my scenario. I have a pretty generic set up. I have a loading screen state where I subscribe to the onLoadComplete signal which 99.9% of the time seems to be running fine. However, over night I had a Raygun (error reporting tool) error pop up with one of our users managing to get a null version number! It is loaded like so ... public create() { this.game.load.onLoadComplete.add(this.loadComplete, this); this.game.load.json("buildInfo", "assets/json/buildinfo.json"); ... } ... public loadComplete() { buildInfo = this.game.cache.getJSON("buildInfo"); Raygun.setVersion("somegame_" + buildInfo.version); ... } The error occurs at "Raygun.setVersion("somegame_" + buildInfo.version);" as buildInfo is undefined. I assume this is some silly load time thing, or perhaps something to do with the way I use getJSON? It's a rare occurrence but it has happened! thought I'd see if anyone with a deeper knowledge of Phaser could fire a few possibilities my way. Thanks! Link to comment Share on other sites More sharing options...
samme Posted April 12, 2017 Share Posted April 12, 2017 20 hours ago, NewGuy said: The error occurs at "Raygun.setVersion("somegame_" + buildInfo.version);" as buildInfo is undefined. You can get loadComplete if the JSON fetch has failed (but completed). In that case the JSON item would be missing from the cache. Can I ask why you're not using the preload/create hooks instead of loadComplete? Link to comment Share on other sites More sharing options...
NewGuy Posted April 17, 2017 Author Share Posted April 17, 2017 On 4/13/2017 at 7:45 AM, samme said: You can get loadComplete if the JSON fetch has failed (but completed). In that case the JSON item would be missing from the cache. Can I ask why you're not using the preload/create hooks instead of loadComplete? Ah thankyou! That would makes sense, my only other idea was that the JSON either didn't exist or was failing at times, hmmm ... As to how I load, my understanding was there was no actual loading going on until you called game.load.start() so my general flow is create (state started) > prepare load stack > load start > on load complete, move on to next state. That to me just seems a little more structured, probably just personal preference in the end, however. snowbillr 1 Link to comment Share on other sites More sharing options...
samme Posted April 18, 2017 Share Posted April 18, 2017 If you use the preload/create callbacks, there's no need to start the loader or bind to its complete event. Link to comment Share on other sites More sharing options...
NewGuy Posted April 18, 2017 Author Share Posted April 18, 2017 6 hours ago, samme said: If you use the preload/create callbacks, there's no need to start the loader or bind to its complete event. Seems like a nice shorthand method, yeah I know I don't need to go all out but I like the structured approach to the loader. Again, just personal preference I think at that point, not sure there's a gain/loss to either method? (if there is pls tell me) Link to comment Share on other sites More sharing options...
samme Posted April 19, 2017 Share Posted April 19, 2017 I think people have recommended you instantiate your own Loader if you're using it separately. I don't remember why. Link to comment Share on other sites More sharing options...
Fenopiù Posted November 28, 2017 Share Posted November 28, 2017 I've tryied too with Phaser 2.6.2, game.load.onLoadComplete.add(function () {alert('Completed loading all assets.');}); in my Preload is called before the start of any upload, even if the last thing of it. I've avoided the problem with a simple if (game.load.progress == 100) {alert('Completed loading all assets.');} Quoting the onLoadComplete doc: Quote This event is dispatched when the final file in the load queue has either loaded or failed. No, in Phaser 2.6.2 it doesn't work as it said, at all. Link to comment Share on other sites More sharing options...
Recommended Posts