Limit sound concurrency

This commit is contained in:
Caitlin Hennessy 2017-12-07 11:27:29 -08:00
parent 064d6f9411
commit 4e4aa266d5

View File

@ -256,6 +256,9 @@ namespace sounds {
}
namespace music {
let numSoundsPlaying = 0;
let soundsLimit = 3;
/**
* Plays a sound
* @param sound the sound to play
@ -284,7 +287,8 @@ namespace music {
//% blockId=music_play_sound_effect block="play sound effect %sound"
//% weight=99
export function playSoundEffect(sound: Sound) {
if (!sound) return;
control.runInBackground(() => sound.play());
if (!sound || numSoundsPlaying >= soundsLimit) return;
numSoundsPlaying++;
control.runInBackground(() => {sound.play(); numSoundsPlaying--;});
}
}