hey, im making a jigsaw game and i would like a different click sound for each piece, but i can only seem to manage one sound for all of them. is there anyway to go about this? here is the section of code for drag elements and the sound.
thanks!
for (var key in pieces) {
var sound_click = new Audio("sounds/click.wav");
var sound_click2 = new Audio("sounds/click2.wav");
// anonymous function to induce scope
(function(){
var privKey = key;
var jig = pieces[key];
Each piece will need a unique id (or even a custom attribute) and then based on the id you can determine which sound should be played for it. I think I would just make an array of audio files and an array of pieces and based on the index of a piece use the same index out of the audio array for the pieces sound.
Bookmarks