0

Im trying to play a pop sound whenever a ball is touched but if the ball is touched again, before the pop sound ends, the sound will not play. I want the pop sound to cut out and start playing again if the ball is touched over and over again. The code i have now is below...

      let popSound = NSBundle.mainBundle().URLForResource("pop",withExtension: "wav")
      let Pop = AVAudioPlayer(contentsOfURL: popSound, error: nil)

 ////this is in the touches begin function/////

      if touchedNode==ball{
        Pop.play()
    }
 //////////////////////////////////
sangony
  • 11,636
  • 4
  • 39
  • 55
drewvy22
  • 65
  • 1
  • 8

1 Answers1

1

I fixed it with the help of this post. AVAudioPlayer stop a sound and play it from the beginning I needed to set the Pop.currentTime to = 0

 if touchedNode==ball{
 Pop.currentTime=0
 Pop.play()
 }
Community
  • 1
  • 1
drewvy22
  • 65
  • 1
  • 8