Fix duplicate music and ambiences

master
Talon 2021-11-05 22:26:13 +01:00
parent 897c912d67
commit 6d0548455e
1 changed files with 6 additions and 8 deletions

View File

@ -6,8 +6,6 @@ export default class Sound {
this.res = new Resonator();
this.ambience = null;
this.music = null;
this.previousAmbience = null;
this.previousMusic = null;
this.ambienceVolume = 1;
this.musicVolume = 1;
this.sfxVolume = 1;
@ -21,10 +19,10 @@ export default class Sound {
async setAmbience(file) {
if (this.ambience) {
this.previousAmbience = this.ambience;
const previousAmbience = this.ambience;
this.ambience = null;
setTimeout(() => this.previousAmbience.fadeOut(6), 1500);
// setTimeout(() => this.previousAmbience.destroy(), 6000);
setTimeout(() => previousAmbience.fadeOut(6), 1500);
setTimeout(() => previousAmbience.destroy(), 6000);
}
if (!file) return;
this.ambience = this.res.stream(file, 0);
@ -36,9 +34,9 @@ export default class Sound {
setMusic(file) {
if (this.music) {
this.previousMusic = this.music;
setTimeout(() => this.previousMusic.fadeOut(2), 500);
setTimeout(() => this.previousMusic.destroy(), 2000);
const previousMusic = this.music;
setTimeout(() => previousMusic.fadeOut(2), 500);
setTimeout(() => previousMusic.destroy(), 2000);
}
if (!file) return;
this.music = this.res.stream(file, 1);