1 // 先声明一个SoundEffect和一个SoundEffectInstance
 2 SoundEffect bgm;
 3 SoundEffectInstance bgmInstance;
 4 
 5 
 6 // 然后在LoadContent中载入背景音乐。在这里用bgm.wav举例
 7 protected override void LoadContent()
 8 {
 9     bgm = Content.Load<SoundEffect>(@"Sounds\bgm");
10     bgmInstance = bgm.CreateInstance();
11 }
12 
13 // 再到Update方法中
14 protected override void Update(GameTime gameTime)
15 {
16     if (bgmInstance.State == SoundState.Stopped)
17         bgmInstance.Play();
18 }

其实就是要用SoundEffectInstance的State属性啦= =

 

忘记说了,如果背景音乐是MP3格式,那就要用MediaPlayer播放 = = 不过那个好像更简单

protected override void Update(GameTime gameTime)
{
    MediaPlayer.IsRepeating = true;
    MediaPlayer.Play(Content.Load<Song>("Sounds/bgm"));
}

 

posted on 2012-04-22 11:12  The_Fake  阅读(533)  评论(0编辑  收藏  举报