[英]Stopping Music in SpriteKit when leaving a GameScene
我已经使用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)
}
在选择下一个场景之前,先停止AVAudioPlayer
在您的序列号之前插入此代码
audioPlayer.pause()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.