33 lines
627 B
JavaScript
33 lines
627 B
JavaScript
export default class ImageLoader
|
|
{
|
|
images = [];
|
|
numberImagesLoaded = 0;
|
|
|
|
update()
|
|
{
|
|
this.numberImagesLoaded++;
|
|
|
|
if (this.numberImagesLoaded === this.images.length) {
|
|
window.dispatchEvent(new Event('imagesloaded'));
|
|
}
|
|
}
|
|
|
|
getCurrentProgress()
|
|
{
|
|
return this.numberImagesLoaded / this.images.length;
|
|
}
|
|
|
|
addImage(imagePath)
|
|
{
|
|
let image = new Image();
|
|
image.src = imagePath;
|
|
image.addEventListener(
|
|
'load', () => {
|
|
this.update();
|
|
}
|
|
);
|
|
|
|
this.images.push(image);
|
|
}
|
|
}
|