我该如何调整XNA窗口的大小。
默认情况下,它以800x600分辨率开始。
从XNA 4.0开始,此属性现在可以在GraphicsDeviceManager
上找到。也就是说,这段代码将会放在你游戏的构造函数中。
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();
我发现您需要设置
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();