0

i am a swift beginner trying to build a game with a sound in it. i use swift SpriteKit and also AVFoundation as my sound starter. Below is the action i call whenever i want a sound action in the game. The sound (background music) plays alright but just wouldn't stop when the game is over.

self.runAction(SKAction.playSoundFileNamed("Sound/Gameplay.wav", waitForCompletion: false))

Can somebody please help me get this issue behind me? thanks.

1 Answers1

0

You could pause and resume the music?

var gameMusic = AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("Gameplay", ofType: "wav")!), error: nil)

//call playBackgroundMusic func
playBackgroundMusic()

func playBackgroundMusic(){
    gameMusic.play()
}

func pauseBackgroundMusic(){
    gameMusic.pause()
}

if(gameOver){
    pauseBackgroundMusic()
}
Danny Law
  • 107
  • 1
  • 5