XNA 音效大幅减慢系统速度
我刚刚完成了非常有用的初学者教程 http://www.riemers.net/eng/Tutorials/XNA/Csharp/series2d.php 我对结果相当满意。
然而,我注意到通过使用 3 个 .wav 文件作为音效,游戏速度大大减慢,我改编了这段代码:
if (keybState.IsKeyDown(Keys.Enter) || keybState.IsKeyDown(Keys.Space))
{
if (!rocketFlying) launch.Play();
rocketFlying = true;
...
}
按下按钮时播放启动音效,因为更新方法检查此 60一秒钟播放一次,而且很难那么快地按下按钮,所以现在只播放一次。
然而,它仍然大大减慢了游戏速度,这显然并不理想。
显然,我并不想对这个特定的游戏做任何事情,但我想知道如何为未来的项目解决这个问题,只是因为它有点令人恼火。
干杯 瑞安
I have just run through the very useful begginers tutorial at http://www.riemers.net/eng/Tutorials/XNA/Csharp/series2d.php and am reasonably happy with the outcome.
However, I have noticed that by using 3 .wav files for the sound effects, the game is massively slowed down, I have adapted this bit of code:
if (keybState.IsKeyDown(Keys.Enter) || keybState.IsKeyDown(Keys.Space))
{
if (!rocketFlying) launch.Play();
rocketFlying = true;
...
}
which plays the launch soundeffect when the button is pressed, as the update method check this 60 times a second, and it is hard to press the button that quickly, so it now only plays it once.
However, it still slows the game down massively, which is obviously not ideal.
Obviously, I am not trying to do anything with this particular game, but I would like to know how to sort out this problem for future projects and just because it is a tad irritating.
Cheers
Ryan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是:假设您以 60 fps 运行。如果你按住按键 1 秒,你的音效将触发 60 次(注意你只检查 .IsKeyDown,只检查一次,你需要检查它是否刚刚按下,而不是它是否按下),
所以你有几个解决方案:
1) 您仅在第一次按下时发出
2) 您进入 xact 项目并将提示或类别的最大实例限制为合理的值 ( 3 是一个很好的数字,使用替换最古老的)
虽然您可能会想做#1,最好的解决方案是#2,因为它向您介绍如何在全球范围内正确限制声音排放,而且还有很多与您相关的很酷的 xact 东西当您知道时可以做(改变音高,随机选择其他声音等)。
here is the problem: say you are running at 60 fps. if you hold down the key for 1 second, your sound effect will fire 60 times (note you are only checking .IsKeyDown, to only check once you need to check if it was just pressed, not if it's down)
so you have a couple solutions:
1) you only emit on the first press
2) you go into your xact project and limit the maximum instances of your cue, or the category, to something reasonable (3 is a good number, using replace oldest)
while you may be tempted to do #1, the best solution is #2, as it introduces you to how to properly limit sound emissions globally, plus there is a lot of cool related xact stuff you can do when you know (vary pitch, randomly pick other sounds, etc).