Upvote:6

Aprove answer
// For background audio (playing continuously)
SKTAudio.sharedInstance().playBackgroundMusic("yourBackgroundMusic.mp3") // Start the music
SKTAudio.sharedInstance().pauseBackgroundMusic() // Pause the music
SKTAudio.sharedInstance().resumeBackgroundMusic() // Resume the music

// For short sounds
SKTAudio.sharedInstance().playSoundEffect("sound.wav") // Play the sound once

Upvote:0

func playerhitfx() {
    let fx:SKAudioNode = SKAudioNode(fileNamed: "playerfx")
    let play: SKAction = SKAction.play()
    let stop: SKAction = SKAction.stop()
    let shade: SKAction = SKAction.colorize(with: UIColor.clear, colorBlendFactor: 1, duration: 1)
    let volume: SKAction = SKAction.changeVolume(to: 3, duration: 0)
    let seq: SKAction = SKAction.sequence([play,shade,stop])
    fx.run(seq)
    fx.run(volume)
    self.addChild(fx)


}

Credit Goes to: stackoverflow.com

Related question with same questions but different answers