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

C# XNA/单游戏音效和音乐正在减慢我的游戏速度,c#,audio,xna,instance,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(); Gam

我做错了什么

音乐和音效让我的游戏慢了很多,有明显的延迟和口吃。 我用的是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();
Game1.instance.Stop();
Game1.bgfeffect.Dispose();
Game1.bgfect=Content.Load(“../../../../Content/Sound/track”+Player.Age);
Game1.instance=Game1.bgfect.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();
if(Game1.fireSoundEffect!=null)
{
Game1.fireSoundInstance.Stop();
Game1.fireSoundEffect.Dispose();
}
Game1.fireSoundEffect=Content.Load(“../../../../Content/Sound/fire”+Player.Age);
游戏1.fireSoundEffect.Play((浮点数)0.3,(浮点数)0.0,(浮点数)0.0);
Game1.fireSoundInstance=Game1.fireSoundEffect.CreateInstance();
Game1.fireSoundInstance.Play();

我感觉不是没有完全处理对象,就是没有停止实例的运行。如何修复此问题?

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

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