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
はい、1秒です –