www.webdeveloper.com
Results 1 to 3 of 3

Thread: separate sounds for multiple draggable elements

Hybrid View

  1. #1
    Join Date
    Apr 2012
    Posts
    2

    separate sounds for multiple draggable elements

    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];

    var jigsaw = new Kinetic.Image({
    image: images[key],
    x: jig.x,
    y: jig.y,
    draggable: true
    });
    jigsaw.on("dragstart", function(){
    jigsaw.moveToTop();
    jigsawLayer.draw();
    sound_click.play() ;
    });

  2. #2
    Join Date
    Jan 2012
    Posts
    31
    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.

  3. #3
    Join Date
    Apr 2012
    Posts
    2
    makes sense to me! thank you

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles