I'm having an issue and would really like it if someone could help out, basically I have a sequence of two sounds that are set to repeat forever. However, I want it so that I can trigger the sound to stop.
All I really need to know is:
In Swift 3 SpriteKit, what code do I use to stop, or pause, a repeating sequence of sounds indefinitely?
Edit: I was using SKActions to play the sounds, the issue has now been solved.
Always good practice to show some code on stack overflow, with your current question we can only take guesses.
If you are using SKActions for sound you can give the repeat action a key and remove that action later. Create the key like so
class GameScene: SKScene {
let soundKey = "RemoveSoundKey" // this avoids typos
}
and than change your action to this
let repeatAction = SKAction.repeatActionForever(YOURSOUNDACTION)
run(repeatAction, withKey: soundKey)
Than you can say
removeAction(forKey: soundKey)
when you want to stop the repeat action.
Note: If you run the action on a node e.g
player.run(repeatAction...)
dont forget to call the remove action on the node
player.removeAction(forKey: soundKey)
Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With