Why is there a lag in my game everytime my sound is being played in swift?

100 views Asked by At

The sound plays everytime I tap the screen but there is a slight hiccup in the game where you could see it lag the screen. How would I fix this?

class level1: SKScene, SKPhysicsContactDelegate, GKGameCenterControllerDelegate {

    var jumpSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("tapsound", ofType: "wav")!)

    var jumpAudioPlayer = AVAudioPlayer()


    override func didMoveToView(view: SKView) {

    jumpAudioPlayer = AVAudioPlayer(contentsOfURL: jumpSound, error: nil)
    jumpAudioPlayer.prepareToPlay()



    }



    override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {

    theHero.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 200))
    jumpAudioPlayer.play()

    }


    }
1

There are 1 answers

5
Fuad On BEST ANSWER

lower the quality/bitrate of the audio that you play.