-
Notifications
You must be signed in to change notification settings - Fork 0
/
Musicmodule.js
44 lines (39 loc) · 972 Bytes
/
Musicmodule.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
class Musicmodule
{
constructor(soundFile, start, full1, full2, end, volumeScale)
{
this.sound = new Howl({
src: ['assets/sound/' + soundFile],
autoplay: false,
loop: true,
volume: 0.0,
onload: function() {
loadedSound();
}
});
this.volume = 0.0;
this.volumeScale = volumeScale;
this.start = start;
this.full1 = full1;
this.full2 = full2;
this.end = end;
}
update(sideGain)
{
if(VIEWPOSITION > this.start && VIEWPOSITION < this.end)
{
if(VIEWPOSITION < this.full1)
this.volume = mapToRange(VIEWPOSITION, this.start, this.full1, 0.0, this.volumeScale);
else if (VIEWPOSITION < this.full2)
this.volume = this.volumeScale;
else
this.volume = mapToRange(VIEWPOSITION, this.full2, this.end, this.volumeScale, 0.0);
}
else
{
this.volume = 0;
}
let newVolume = this.volume * sideGain;
this.sound.volume(newVolume);
}
}