关于XNA游戏中循环播放背景音乐【wav / mp3】

 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"));
}

 

转载于:https://www.cnblogs.com/thefake/articles/2464776.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值