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 effects = this.getSoundEffects(soundId);
const player = this.getSoundPlayer(soundId); const player = this.getSoundPlayer(soundId);
this.playerTargets.set(soundId, target); if (this.playerTargets.get(soundId) !== target) {
effects.setEffectsFromTarget(target); // make sure to stop the old sound, effectively "forking" the output
effects.addSoundPlayer(player); // 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.connect(effects);
player.play(); player.play();
return player.finished(); return player.finished();