AVAudioPlayer导致游戏延迟

编程入门 行业动态 更新时间:2024-10-23 17:25:46
本文介绍了AVAudioPlayer导致游戏延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个简单的游戏,您在火箭里,可以避免屏幕上掉落的行星.当我播放短短的亚秒长声音时,我的游戏在播放时会出现抖动和滞后现象,然后恢复正常.有谁知道为什么会这样吗?

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导致游戏延迟

本文发布于:2023-11-23 14:09:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621718.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:游戏   AVAudioPlayer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!