0

I have a sound instance that plays when the player collides with an object.

  var coin = new Audio('sounds/coin.wav');
  if(type == 2){  //Coin Box
    coin.play();
  }

The problem is , when the player collides with multiple objects of the same kind, the sound doesnt play again as it is already playing. How do i stop the previous sound and play it again? also without having to create another instance of the same sound.

Something like this.

    if(type == 2){ 
      coin.pause();
      coin.play();
    }
T0xicCode
  • 4,583
  • 2
  • 37
  • 50
Pratish Shrestha
  • 1,712
  • 4
  • 17
  • 26

1 Answers1

2

Set the time back to the start.

coin.pause();
coin.currentTime = 0;
coin.play();
epascarello
  • 204,599
  • 20
  • 195
  • 236