1
我使用AVFoundation在我的遊戲中實現了背景音樂。但是,當離開GameScene時,音樂繼續播放。我知道在viewController中你可以使用viewWillDisappear,但是我找不到任何與GameScenes類似的東西。在離開GameScene時在SpriteKit中停止音樂
var audioPlayer = AVAudioPlayer()
let audioPath = Bundle.main.path(forResource: "electroDrive", ofType: "wav")
//.......//
//.......//
do {
try audioPlayer = AVAudioPlayer(contentsOf: URL(fileURLWithPath: audioPath!))
}
catch {
// process error
}
audioPlayer.play()
//Code to go to other scene
if viewController != nil {
self.viewController?.performSegue(withIdentifier: "push", sender: viewController)
}
您可以顯示當你去到下一個場景的代碼? – Jack
是的,給我一秒 –