Burundanga
Burundanga

Reputation: 668

How to stop sound from playing in SpriteKit?

I have a background music and sounds in a game. There are some moments that I don't want them to execute. I use

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {    
let jump = SKAction.playSoundFileNamed("Jump.wav", waitForCompletion: false)
self.runAction(jump)
        }

for playing it, but it continue to play every time i tap the screen and I don't want it to execute when game over node already appeared, for example. Apple docs says that this action is not reversible. So how can I stop it?

Upvotes: 1

Views: 567

Answers (1)

sangony
sangony

Reputation: 11696

Using SKAction to play sound gives you no control once it starts. Instead I suggest you use AVAudioPlayer which allows you to stop playing at any time.

Upvotes: 1

Related Questions