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,123
  • 2
  • 32
  • 49
Pratish Shrestha
  • 1,382
  • 3
  • 15
  • 26

1 Answers1

2

Set the time back to the start.

coin.pause();
coin.currentTime = 0;
coin.play();
epascarello
  • 195,511
  • 20
  • 184
  • 225