我正在尝试在菜单状态下播放音乐,但在切换到游戏状态后会中断。
问问题
1600 次
1 回答
1
MediaPlayer 类具有 Play() 和 Stop() 方法。这里是 MSDN 链接:
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.media.mediaplayer.play.aspx http://msdn.microsoft.com/en-us/library/microsoft.xna.framework .media.mediaplayer.stop.aspx
如果我没记错的话,你可以这样做:
// Variable declaration
Song menu_song;
Song game_song;
bool isInMenu; //I'll use this instead of the gamestate as example
//In the LoadContent method:
//remember to add the song to your project. In this case is in
//a folder called "music"
Content.Load<Song>("music/menuSongName");
Content.Load<Song>("music/gameSongName");
//In Update method:
if (isInMenu)
{
MediaPlayer.Stop(); //Stop the current audio...
MediaPlayer.Play(menu_song); //...and start playing the next.
}
else
{
MediaPlayer.Stop(); //Stop the current audio
MediaPlayer.Play(game_song); //...and start playing the next.
}
我没有检查这个代码,如果你有什么问题,请告诉我,我会检查它。=) 游戏状态也是如此,我想你会知道如何根据你的需要调整这段代码。
于 2013-04-28T14:47:19.537 回答