XNA / MonoGame的声音影响和音乐正在减慢我的游戏速度

时间:2014-09-05 06:39:21

标签: c# audio xna instance

我做错了什么?

音乐和声音效果正在减慢我的游戏速度,有明显的滞后和口吃。 我正在使用MonoGame。

音乐:

Game1.instance.Stop();
Game1.bgEffect.Dispose();
Game1.bgEffect = Content.Load<SoundEffect>("../../../../Content/Sound/track" + Player.Age);
Game1.instance = Game1.bgEffect.CreateInstance();
Game1.instance.Play();

音效:

if (Game1.fireSoundEffect != null)
{
     Game1.fireSoundInstance.Stop();
     Game1.fireSoundEffect.Dispose();
}

Game1.fireSoundEffect = Content.Load<SoundEffect>("../../../../Content/Sound/fire" + Player.Age);
Game1.fireSoundEffect.Play((float)0.3, (float)0.0, (float)0.0);
Game1.fireSoundInstance = Game1.fireSoundEffect.CreateInstance();
Game1.fireSoundInstance.Play();

我有一种感觉,我要么不完全处理对象,要么不停止运行实例。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

看起来你正在加载来自内容管道的文件,初始化对象,然后在你的Update循环中同时播放所有声音。

您需要做的是在LoadContent函数(或任何其他init函数)中加载和初始化您的内容。然后在Update循环中,您只需在需要时调用Play()函数。