mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-05-28 00:01:54 +08:00
prevent same sound from playing multiple times
This commit is contained in:
@@ -51,9 +51,21 @@ var AudioEngine = {
|
||||
},
|
||||
_playSound: function (buffer) {
|
||||
if (!AudioEngine._canPlayAudio()) return;
|
||||
if (AudioEngine._currentSoundEffectAudio &&
|
||||
AudioEngine._currentSoundEffectAudio.source.buffer == buffer) {
|
||||
return;
|
||||
}
|
||||
|
||||
var source = AudioEngine._audioContext.createBufferSource();
|
||||
source.buffer = buffer;
|
||||
source.onended = function(event) {
|
||||
// dereference current sound effect when finished
|
||||
if (AudioEngine._currentSoundEffectAudio &&
|
||||
AudioEngine._currentSoundEffectAudio.source.buffer == buffer) {
|
||||
AudioEngine._currentSoundEffectAudio = null;
|
||||
}
|
||||
};
|
||||
|
||||
source.connect(AudioEngine._master);
|
||||
source.start();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user