From 6d0548455e3f43f5365ff74b25d705635308cbd8 Mon Sep 17 00:00:00 2001 From: Talon Date: Fri, 5 Nov 2021 22:26:13 +0100 Subject: [PATCH] Fix duplicate music and ambiences --- src/engine/sound.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/engine/sound.js b/src/engine/sound.js index 8aea485..bfcd2d5 100644 --- a/src/engine/sound.js +++ b/src/engine/sound.js @@ -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);