- Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAssets.js
More file actions
Latest commit
57 lines (40 loc) · 1.23 KB
/
Copy pathAssets.js
File metadata and controls
57 lines (40 loc) · 1.23 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
letsprites={};
letassetsStillLoading=0;
functionassetsLoadingLoop(callback){
if(assetsStillLoading){
requestAnimationFrame(assetsLoadingLoop.bind(this,callback));
}
else{
callback();
}
}
functionloadAssets(callback){
functionloadSprite(fileName){
assetsStillLoading++;
letspriteImage=newImage();
spriteImage.src="./assets/sprites/"+fileName;
spriteImage.onload=function(){
assetsStillLoading--;
}
returnspriteImage;
}
sprites.background=loadSprite('spr_background.png');
sprites.stick=loadSprite('spr_stick.png');
sprites.whiteBall=loadSprite('spr_whiteBall.png');
sprites.redBall=loadSprite('spr_redBall.png');
sprites.yellowBall=loadSprite('spr_yellowBall.png');
sprites.blackBall=loadSprite('spr_blackBall.png');
assetsLoadingLoop(callback);
}
functiongetBallSpriteByColor(color){
switch(color){
caseCOLOR.RED:
returnsprites.redBall;
caseCOLOR.YELLOW:
returnsprites.yellowBall;
caseCOLOR.BLACK:
returnsprites.blackBall;
caseCOLOR.WHITE:
returnsprites.whiteBall;
}
}