Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Phaser - Custom Preload Animation


Nick
 Share

Recommended Posts

I'm creating a custom preload animation for my game and need to access the progress of the loader so I can display it as a percentage. Currently I'm using the following code within my game's 'preload' function.

this.load.onFileComplete.add(function( progress ) {    // Display value of progress here});
As expected the value of progress only updates when each individual file is loaded completely which is not ideal as I'm only loading 2 large images, so it simply jumps from 0% > 50% > 100%. Preferably I'd like to display the progress of the files as they are being loaded.

Is there another method I can use which will give me updates of the progress while the file is loading? I can't see anything in the docs but I'm guessing the built in preloadSprite is able to access this data in some way.

Thanks.

Link to comment
Share on other sites

I'm new to Javascript, but is there a way to get the number of bytes for each image? If so you can simply add them together to get the total bytes needing to be loaded, then for your bar, round up the result of bytes loaded divided by the total bytes to get a percentage. That's how i did it in an old game i wrote in qbasic, lol!

Sorry about mistakes, I'm on my phone.

Link to comment
Share on other sites

FYI - as Nick noted, loader progress is only granular to the file level. the reason for this is that javascript only receives callbacks when items are completely loaded. XmlHttpRequest Level 2 provides new capabilities for getting progress notifications (in addition to lots of other good stuff), but it's support is not universal (see http://caniuse.com/xhr2).

 

perhaps someday soon we'll have real, granular loading progress :)

Link to comment
Share on other sites

  • 8 months later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...