-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.js
72 lines (54 loc) · 1.25 KB
/
Menu.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
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
function Menu(){
}
Menu.prototype.init = function
(
backgroundSprite,
labels,
buttons,
sound
){
this.background = backgroundSprite;
this.labels = labels || [];
this.buttons = buttons || [];
this.sound = sound ? sound : undefined;
this.active = false;
}
Menu.prototype.load = function(){
this.sound.currentTime = 0;
this.active = true;
requestAnimationFrame(this.menuLoop.bind(this));
if(SOUND_ON){
this.sound.volume = 0.8;
}
this.sound.play();
}
Menu.prototype.draw = function(){
Canvas2D._canvas.style.cursor = "auto";
Canvas2D.drawImage(
this.background,
Vector2.zero,
0,
1,
Vector2.zero
);
for(let i = 0 ; i < this.labels.length ; i++){
this.labels[i].draw();
}
for(let i = 0 ; i < this.buttons.length ; i++){
this.buttons[i].draw();
}
}
Menu.prototype.handleInput = function(){
for(let i = 0 ; i < this.buttons.length ; i++){
this.buttons[i].handleInput();
}
}
Menu.prototype.menuLoop = function(){
if(this.active){
this.handleInput();
Canvas2D.clear();
this.draw();
Mouse.reset();
requestAnimationFrame(this.menuLoop.bind(this));
}
}