从窗口模式转到全屏模式

时间:2013-08-22 14:07:39

标签: c# xna window fullscreen xna-4.0

好的,我想要的是在gameState.gameLoading之后将从窗口模式切换到全屏的代码,以便下一个gameState.mainMenu状态为全屏。我怎么做?我的代码是:变量:

    //Game States
    public enum gameState
    {
        gameLoading,
        mainMenu,
        gameOptions,
        levelSelect,
        gamePlaying,
        gameOver
    }
    gameState CurrentGameState = gameState.gameLoading;

Update()方法:

        if (CurrentGameState != gameState.gameLoading)
        {
            IsMouseVisible = false;
            graphics.IsFullScreen = true;
        }
        if (CurrentGameState == gameState.gameLoading)
        {
            IsMouseVisible = true;
            graphics.IsFullScreen = false;
        }

但它不起作用。有什么建议吗?

3 个答案:

答案 0 :(得分:1)

您需要应用图形更改,如下所示:

graphics.IsFullScreen = true;
graphics.ApplyChanges();
// profit

答案 1 :(得分:0)

Here您可以使用graphics.ToggleFullScreen()检查您获得的例外情况。

答案 2 :(得分:0)

我找到的解决方案是:

        //Update() method
        if (CurrentGameState == gameState.gameLoading)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Enter))
            {
                graphics.ToggleFullScreen(); //?
            }
            graphics.ApplyChanges();
        }