我有一个简单的游戏,您在火箭里,可以避免屏幕上掉落的行星.当我播放短短的亚秒长声音时,我的游戏在播放时会出现抖动和滞后现象,然后恢复正常.有谁知道为什么会这样吗?
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?
推荐答案AVAudioPlayer虽然声音在其他线程上播放,但会导致长时间的延迟,无法在其当前线程上初始化自身.
AVAudioPlayer, while the sound plays on a different thread, will cause a long delay initializing itself on its current thread.
我的解决方案是仅将AVAudioPlayer用于音乐,因为高级API对此很有用,但即使如此,还是要这样做:
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.
我通过直接将OpenAL用于声音效果解决了这一问题.没有抖动,没有延迟.
I solved this by using OpenAL directly for sound effects. No Jitter, no lag.
更多推荐
AVAudioPlayer导致游戏延迟
发布评论