-
Notifications
You must be signed in to change notification settings - Fork 0
/
resources.js
40 lines (35 loc) · 971 Bytes
/
resources.js
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
RFall.resources = { }
RFall.resources.images = { }
RFall.resources.sources = {
playerLeft: "imgs/playerLeft.png",
playerRight: "imgs/playerRight.png",
playerHurtLeft: "imgs/playerHurtLeft.png",
playerHurtRight: "imgs/playerHurtRight.png",
mineShaft: "imgs/mineShaft.gif",
cage: "imgs/cage.png",
rock: "imgs/rock.png",
heart: "imgs/heart.png",
paused: "imgs/paused.png",
splash: "imgs/splash.png"
}
RFall.resources.loadImages = function( callback ) {
var images = RFall.resources.images
var loadedImages = 0
var numImages = 0
var sources = RFall.resources.sources
// Count the number of images
for (var src in sources) {
numImages++
}
// Instantiate, check for completed loading, link to source
for (var src in sources) {
images[src] = new Image()
images[src].onload = function () {
++loadedImages
if (loadedImages == numImages) {
callback()
}
}
images[src].src = sources[src]
}
}