I'am programming a Javascript game and I want to use one sound in multiple times. I can do it with loading one sound more times to an array. But I want to load one sound once and "copy" it to array, so I can play it multiple times. This is method what I have now:
this.list = [
"LaserShot", //http://www.freesound.org/samplesViewSingle.php?id=39459
"Ding", //http://www.freesound.org/samplesViewSingle.php?id=5212
"Rocket" //http://www.freesound.org/samplesViewSingle.php?id=47252 -> http://creativecommons.org/licenses/sampling+/1.0/
];
...
for (i in this.list) {
this.sounds[this.list[i]] = new Array();
for (var j = 0; j < this.channels; j++) {
this.sounds[this.list[i]][j] = new Audio("./sounds/"+ this.list[i] + type);
}
}
I just want to do this:
for (i in this.list) {
this.sounds[this.list[i]] = new Array();
var tempAudio = new Audio("./sounds/"+ this.list[i] + type);
for (var j = 0; j < this.channels; j++) {
this.sounds[this.list[i]][j] = realCopyOfTempAudio;
}
}
Thank you so much.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…