关于ios:为什么每次我的声音快速播放时我的游戏都会有延迟?

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

每次我点击屏幕时都会播放声音,但游戏中有轻微的打嗝,您可以看到它滞后于屏幕。我将如何解决这个问题?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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()

    }


    }

降低您播放的音频的质量/比特率。