【发布时间】:2010-10-17 18:03:16
【问题描述】:
如何在 XNA 中调整窗口的大小。
默认以 800x600 分辨率开始。
【问题讨论】:
标签: xna fullscreen
如何在 XNA 中调整窗口的大小。
默认以 800x600 分辨率开始。
【问题讨论】:
标签: xna fullscreen
我发现你需要设置
GraphicDevice.PreferredBackBufferHeight = height;
GraphicDevice.PreferredBackBufferWidth = width;
当您在游戏类的构造函数中执行此操作时,它可以工作,但是当您尝试在构造函数之外执行此操作时,您还需要调用
GraphicsDevice.ApplyChanges();
此外,您可以使用全屏(调试时无法正常工作)
if (!GraphicsDevice.IsFullScreen)
GraphicsDevice.ToggleFullScreen();
【讨论】:
【讨论】:
此解决方案适用于 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();
【讨论】:
从 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();
【讨论】: