我正在编写一个Javascript游戏,我想在多次使用一个声音。我可以通过将一个声音多次加载到一个数组中来做到这一点。但是我想加载一次声音并将其“复制”到数组中,这样我就可以多次播放它。这是我现在拥有的方法:
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);
}
}
我只想这么做:
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;
}
}
非常感谢。
https://stackoverflow.com/questions/5194898
复制相似问题