melonjs / melonJS

a fresh, modern & lightweight HTML5 game engine
https://melonjs.org
MIT License
5.77k stars 641 forks source link

[Feature request] More realistic progress based on bytes for loader and preloader #1188

Open cuixiping opened 12 months ago

cuixiping commented 12 months ago

I wish there is a more realistic progress handler based on bytes.

Example code:

let assets = [
     { name : 'image1', src : 'images/image1.png', bytes: 120366 },  // 6.4%
     { name : 'image2', src : 'images/image2.png', bytes: 170214 },  // 9.0%
     { name : 'image3', src : 'images/image3.png', bytes: 192252 },  // 10.2%
     { name : 'binary', src : 'data/binary-data-001', bytes: 1401286 }  // 74.4%
];
let updateProgressDisplay = percent => {
  // do something
};
me.loader.preload(assets,  {
    completed: ()=>this.loaded(),
    progress: (e) => updateProgressDisplay(e.percent)),
});

But it's not a good way if input the bytes numbers manually.

It will be better if some build scripts generate those numbers automatically.

What do you think about it?

.