Whenever I call the following my app gets laggy.
func playSound() {
if soundsOn {
audioPlayer.prepareToPlay()
audioPlayer.play()
}
}
I've already done this in the didMove(to view: SKView):
do {
audioPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: Bundle.main.path(forResource: "ButtonPressSound", ofType: "wav")!))
}
catch {
print(error)
}
The sound plays, but like I mentioned, the app gets laggy; movement of SKNodes gets choppy.
Why does this happen? Is there any way to fix this?