Limit sound concurrency
This commit is contained in:
parent
064d6f9411
commit
4e4aa266d5
@ -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--;});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user