-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybackButton.js
39 lines (33 loc) · 1.03 KB
/
playbackButton.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
//displays and handles clicks on the playback button.
function PlaybackButton() {
this.x = 20;
this.y = 20;
this.width = 20;
this.height = 20;
//flag to determine whether to play or pause after button click and
//to determine which icon to draw
this.playing = false;
this.draw = function() {
if (this.playing) {
rect(this.x, this.y, this.width / 2 - 2, this.height);
rect(this.x + (this.width / 2 + 2), this.y, this.width / 2 - 2, this.height);
}
else {
triangle(this.x, this.y, this.x + this.width, this.y + this.height / 2, this.x, this.y + this.height);
}
};
//checks for clicks on the button, starts or pauses playabck.
//@returns true if clicked false otherwise.
this.hitCheck = function() {
if (mouseX > this.x && mouseX < this.x + this.width && mouseY > this.y && mouseY < this.y + this.height) {
if (sound.isPlaying()) {
sound.pause();
} else {
sound.loop();
}
this.playing = !this.playing;
return true;
}
return false;
};
}