【问题标题】:How do I set the window / screen size in xna?如何在 xna 中设置窗口/屏幕大小?
【发布时间】:2010-10-17 18:03:16
【问题描述】:

如何在 XNA 中调整窗口的大小。

默认以 800x600 分辨率开始。

【问题讨论】:

    标签: xna fullscreen


    【解决方案1】:

    我发现你需要设置

    GraphicDevice.PreferredBackBufferHeight = height;
    GraphicDevice.PreferredBackBufferWidth = width;
    

    当您在游戏类的构造函数中执行此操作时,它可以工作,但是当您尝试在构造函数之外执行此操作时,您还需要调用

    GraphicsDevice.ApplyChanges();
    

    此外,您可以使用全屏(调试时无法正常工作)

    if (!GraphicsDevice.IsFullScreen)
       GraphicsDevice.ToggleFullScreen();
    

    【讨论】:

    • 这个答案有点过时了,所以我建议在下面查看 Fuex 的答案。基本相同,但代码无需任何编辑即可编译。
    【解决方案2】:

    【讨论】:

      【解决方案3】:

      此解决方案适用于 XNA 3.0。只需将其放入游戏对象的构造函数中即可:

      // Resize the screen to 1024 x 768.
      IntPtr ptr = this.Window.Handle;
      System.Windows.Forms.Form form = (System.Windows.Forms.Form)System.Windows.Forms.Control.FromHandle(ptr);
      form.Size = new System.Drawing.Size(1024, 768);
      
      graphics.PreferredBackBufferWidth = 1024;
      graphics.PreferredBackBufferHeight = 768;
      
      graphics.ApplyChanges();
      

      【讨论】:

        【解决方案4】:

        从 XNA 4.0 开始,此属性现在可以在 GraphicsDeviceManager 上找到。 IE。此代码将进入您的游戏的构造函数中。

        graphics = new GraphicsDeviceManager(this);
        graphics.IsFullScreen = false;
        graphics.PreferredBackBufferHeight = 340;
        graphics.PreferredBackBufferWidth = 480;
        
        // if changing GraphicsDeviceManager properties outside 
        // your game constructor also call:
        // graphics.ApplyChanges();
        

        【讨论】:

        • Sjors Miltenburg 下面的回答现在已经过时了。 Fuex 的这个答案适用于 XNA 4.0。
        • 不过,在此之后您仍然需要执行 graphics.ApplyChanges()。
        猜你喜欢
        • 2014-03-11
        • 2022-06-18
        • 2013-05-28
        • 2010-09-10
        • 2016-12-11
        • 1970-01-01
        • 2013-01-10
        • 2014-12-10
        • 1970-01-01
        相关资源
        最近更新 更多