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
是的,给我一秒 –