【发布时间】:2016-12-15 05:14:45
【问题描述】:
我使用 AVFoundation 在我的游戏中实现了背景音乐。但是,当离开 GameScene 时,音乐会继续播放。我知道在 viewControllers 中你可以使用 viewWillDisappear 但我找不到 GameScenes 类似的东西。
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)
}
【问题讨论】:
-
你能显示下一个场景的代码吗?
-
是的,给我一秒钟
标签: ios swift sprite-kit avfoundation