Better order of stop/connect/play

This commit is contained in:
Corey Frang 2018-06-21 11:13:04 -04:00
parent ea6093835c
commit c8f3510713

View file

@ -90,11 +90,17 @@ class SoundBank {
const effects = this.getSoundEffects(soundId);
const player = this.getSoundPlayer(soundId);
this.playerTargets.set(soundId, target);
effects.setEffectsFromTarget(target);
effects.addSoundPlayer(player);
if (this.playerTargets.get(soundId) !== target) {
// make sure to stop the old sound, effectively "forking" the output
// when the target switches before we adjust it's effects
player.stop();
}
this.playerTargets.set(soundId, target);
effects.addSoundPlayer(player);
effects.setEffectsFromTarget(target);
player.connect(effects);
player.play();
return player.finished();