2016-12-14 10 views
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) 
    } 
+0

前にこれを挿入し、あなたが次のシーンに行くときのためのコードを表示することができますか? – Jack

+0

はい、1秒です –

答えて

2

停止AVAudioPlayer次のシーン

をsegueing前に、あなたのセグエコード

audioPlayer.pause() 
+0

ええ。あなたのコメントを見た瞬間、私はそれを理解しました。ありがとう! –

関連する問題