问题
I have a simple game where you are in a rocket and you avoid planets that come down the screen. When I play a short sub second long sound my game jitters and lags whilst it plays it and then returns to normal. Does any one know why this might be?
回答1:
AVAudioPlayer, while the sound plays on a different thread, will cause a long delay initializing itself on its current thread.
My solution was to use AVAudioPlayer only for music, since the high level API made it useful for that, but even then to do a:
dispatch_async
to a special music queue when I wanted to do any operations around playing music.
For sound effects this technique will work (in terms of not causing jitter), but the sound will be delayed and probably not be good enough.
I solved this by using OpenAL directly for sound effects. No Jitter, no lag.
来源:https://stackoverflow.com/questions/26345857/avaudioplayer-causes-game-lag