Sign in to follow this  
NewGuy

onLoadComplete possibly firing too early?

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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. :)

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.