如何在 XNA 中调整窗口的大小。
默认它以 800x600 分辨率开始。
从 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();
我发现你需要设置
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();