Added logic for removing destroyed sounds from sounds array on BaseSoundManager update call

This commit is contained in:
Pavle Goloskokovic 2018-01-04 19:50:06 +01:00
parent cf31ed9a4d
commit b3fad218bc

View file

@ -194,7 +194,15 @@ var BaseSoundManager = new Class({
* @param {number} delta - The delta time elapsed since the last frame.
*/
update: function (time, delta) {
// TODO remove pending sounds
this.sounds.sort(function (s1, s2) {
return (s1.pendingRemove === s2.pendingRemove) ? 0 : s1 ? 1 : -1;
});
for (var i = this.sounds.length - 1; i >= 0; i--) {
if (!this.sounds[i].pendingRemove) {
this.sounds.splice(this.sounds.length - 1 - i);
break;
}
}
this.sounds.forEach(function (sound) {
sound.update(time, delta);
});