Skip to content

Commit dc47bf3

Browse files
committed
Add removeSoundPlayer
1 parent aee8e10 commit dc47bf3

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎src/SoundBank.js‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,29 @@ class SoundBank {
8080
return this.soundEffects.get(sound);
8181
}
8282

83+
/**
84+
* Remove a single sound player and release its resources.
85+
* @param {string} soundId - the id of the sound player to remove
86+
*/
87+
removeSoundPlayer (soundId) {
88+
const player = this.soundPlayers[soundId];
89+
if (player) {
90+
player.dispose();
91+
delete this.soundPlayers[soundId];
92+
}
93+
94+
const effects = this.soundEffects.get(soundId);
95+
if (effects) {
96+
if (player) {
97+
effects.removeSoundPlayer(player);
98+
}
99+
effects.dispose();
100+
this.soundEffects.delete(soundId);
101+
}
102+
103+
this.playerTargets.delete(soundId);
104+
}
105+
83106
/**
84107
* Play a sound.
85108
* @param {Target} target - Target to play for

0 commit comments

Comments
 (0)