2016-12-14 1 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이 당신의 SEGUE 코드 전에 다음 장면

삽입에 segueing 전에

audioPlayer.pause() 
+0

예. 내가 당신의 코멘트를 보았을 때 나는 그것을 알아 냈다. 고마워요! –