This repository was archived by the owner on Dec 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloading.js
More file actions
88 lines (79 loc) · 1.97 KB
/
Copy pathloading.js
File metadata and controls
88 lines (79 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*~~ Declare assets to load behind loading screen ~~*/
// If you're using more sprite sheets or background images, add them here
imgNone = "./images/none.png";
imgCover = "./images/cover.png";
img1 = "./zine/pages/1.png";
img2 = "./zine/pages/2.png";
img3 = "./zine/pages/3.png";
img4 = "./zine/pages/4.png";
img5 = "./zine/pages/5.png";
img6 = "./zine/pages/FRONT.png";
img7 = "./zine/pages/BACK.png";
img8 = "./zine/pages/INNERFRONT.png";
imglace = "./images/lace.png";
imgBG = "./images/bedroom.png";
imgBG2 = "./images/background.png"
// sprites
s1 = "./images/bead_n_b.png";
s2 = "./images/bead_n.png";
s3 = "./images/bead_s_b.png";
s4 = "./images/bead_s.png";
s5 = "./images/freckles_n_b.png";
s6 = "./images/freckles_n.png";
s7 = "./images/freckles_s_b.png";
s8 = "./images/freckles_s.png";
const imageSrcs = [
imgNone,
imgCover,
img1,
img2,
img3,
img4,
img5,
img6,
img7,
img8,
imglace,
imgBG, imgBG2,
s1, s2, s3, s4, s5, s6, s7, s8
];
imagesLoaded = false;
// sound assets
snd1 = "./sounds/typing.mp3";
const soundSrcs = [snd1];
soundsLoaded = false;
allAssetsLoaded = false;
/*~~ Preload assets ~~*/
$(window).load(function () {
window.preloadedImages = [];
imagesLoaded = 0;
totalImages = imageSrcs.length;
imageSrcs.forEach((imgUrl) => {
var img = new Image();
img.src = imgUrl;
img.onload = (e) => {
imagesLoaded++;
window.preloadedImages.push(img);
if (imagesLoaded === totalImages) {
this.imagesLoaded = true;
if (this.imagesLoaded && this.soundsLoaded) {
donePreloading();
}
}
};
});
soundsLoaded = 0;
totalSounds = soundSrcs.length;
soundSrcs.forEach((filename) => {
var audio = new Audio(filename);
audio.addEventListener("canplaythrough", () => {
soundsLoaded++;
if (soundsLoaded === totalSounds) {
this.soundsLoaded = true;
if (this.imagesLoaded && this.soundsLoaded) {
donePreloading();
}
}
});
});
});