-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio.js
More file actions
113 lines (97 loc) · 3.33 KB
/
audio.js
File metadata and controls
113 lines (97 loc) · 3.33 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// music
let music;
let audioRun;
let audioHit;
let audioLand;
let audio = {
// Initial prep for music
prepAudio: function() {
// Setup the background music
music = game.add.audio('bgmusic');
// Decodes all sounds, only after this is complete will startMusic run
game.sound.setDecodedCallback([ music ], audio.startMusic, this);
// Setup callbacks to resume and pause the music
game.onPause.add(audio.pauseMusic, this);
game.onResume.add(audio.resumeMusic, this);
},
// Mute background music
muteMusicVolume: function() {
if (music.mute == true) {
music.mute = false;
audioRun.mute = false;
audioHit.mute = false;
audioLand.mute = false;
} else {
music.mute = true;
audioRun.mute = true;
audioHit.mute = true;
audioLand.mute = true;
}
/*if (player2Group.length > 0) { // Not really sure why this code is even here? wut?
player2Group.forEach(function(player) {controller.controlPlayer(player, player2Group);}, this);
}*/
},
// Increase background music volume
increaseMusicVolume: function() {
if (music.mute == true) {
music.mute = false
}
music.volume += 1;
},
// Decrease background music volume
decreaseMusicVolume: function() {
if (music.volume > 0 && music.mute == true) {
music.mute = false;
}
if (music.volume > 0){
music.volume -= 1;
} else {
music.mute = true;
}
},
// Resume music after a pause
resumeMusic: function() {
music.mute = false;
//music.resumeAll();
music.resume();
},
// Pause background music
pauseMusic: function() {
music.mute = false;
music.pause();
},
// Initial start of background music
startMusic: function() {
music.volume = 0;
music.mute = false;
music.play();
},
getAudioRun: function (player) {
// SoundFX
let audioRun = game.add.audio('run');
game.sound.setDecodedCallback(audioRun, player.setAudioRunReady, this);
return audioRun;
//audioHit = game.add.audio('hit');
//audioLand = game.add.audio('land');
},
audioRunCheck: function (player) {
if (player.isAudioRunReady && !player.isAudioRunPlaying && player.isAudioRunStopped && !player.isCopy) {
player.audioRun.stop();
player.isAudioRunPlaying = true;
player.isAudioRunStopped = false;
player.audioRun.play();
} else if (player.isAudioRunReady && player.isAudioRunPlaying && !player.isAudioRunStopped && !player.isCopy) {
//do nothing because it's playing?
} else if (player.isAudioRunReady && !player.isAudioRunPlaying && !player.isAudioRunStopped && !player.isCopy) {
// The audio is paused because it hasn't finished playing and it's not playing
player.isAudioRunPlaying = true;
player.audioRun.resume();
}
},
audioRunPauseCheck: function (player) {
if (player.isAudioRunReady && player.isAudioRunPlaying && !player.isCopy) {
player.isAudioRunPlaying = false;
player.audioRun.pause();
}
}
};