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



我做错了什么?

音乐和音效让我的比赛节奏慢了很多,有明显的滞后和口吃。我正在使用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();

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

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

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

最新更新