AVAudioPlayer causes game lag

故事扮演 提交于 2019-12-25 01:25:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!