mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
Level class created and gravity editable.
This commit is contained in:
32
js/ImageLoader.js
Normal file
32
js/ImageLoader.js
Normal file
@@ -0,0 +1,32 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user