Nick Posted January 31, 2014 Share Posted January 31, 2014 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 More sharing options...
Nebulocity Posted January 31, 2014 Share Posted January 31, 2014 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 More sharing options...
Nick Posted February 4, 2014 Author Share Posted February 4, 2014 Thanks Nebulosity. I was hoping there may be something built into Phaser for this but I've realised the onFileComplete method is used by preloadSprite so that must be the best option. In retrospect, this actually good enough for my needs. Link to comment Share on other sites More sharing options...
Alvin Posted February 4, 2014 Share Posted February 4, 2014 Hi, you can check the value of "this.load.progress" in your "loadUpdate" function, this value is between 0 and 100 and matches the current loading progress XekeDeath 1 Link to comment Share on other sites More sharing options...
jcs Posted February 4, 2014 Share Posted February 4, 2014 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 More sharing options...
fhefh Posted October 5, 2014 Share Posted October 5, 2014 you can see this example http://examples.phaser.io/_site/view_full.html?d=loader&f=load+events.js&t=load%20events maybe help you ~~~ Link to comment Share on other sites More sharing options...
Recommended Posts