0

有人可以告诉我这里哪里出错了吗?我不断收到错误消息:

“ArgumentNullException 未处理。此方法不接受此参数的 null。参数名称:song”

我找不到解决办法。

Song BGmusic;
bool songstart = false;

protected override void LoadContent()
{
    currentgamescreen = Gamescreen.menuscreen;

    if (!songstart)
    {
        MediaPlayer.Play(BGmusic);
    }

    BGmusic = Game.Content.Load<Song>("audio/rockTheDragon");
}
4

3 回答 3

10

好吧,您调用尚未初始化的地方,因此为空MediaPlayer.Play(BGmusic);BGmusic

可能使它像:

protected override void LoadContent()
{
    currentgamescreen = Gamescreen.menuscreen;

    if (!songstart)
    {
        BGmusic = Game.Content.Load<Song>("audio/rockTheDragon");
        MediaPlayer.Play(BGmusic);
    }
 }

会解决一个问题。

于 2013-01-25T14:53:34.440 回答
2

您在MediaPlayer.Play(BGmusic)BGmusic. 尝试以下操作:

Song BGmusic;
bool songstart = false;

protected override void LoadContent()
{
    currentgamescreen = Gamescreen.menuscreen;

    BGmusic = Game.Content.Load<Song>("audio/rockTheDragon");

    if (!songstart)
    {
        MediaPlayer.Play(BGmusic);
    }
 }
于 2013-01-25T14:54:26.810 回答
1

移动

 BGmusic = Game.Content.Load<Song>("audio/rockTheDragon");

到该方法的顶部

于 2013-01-25T14:54:56.753 回答