55

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

默认它以 800x600 分辨率开始。

4

4 回答 4

71

从 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();
于 2010-04-14T06:01:15.697 回答
60

我发现你需要设置

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

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

GraphicsDevice.ApplyChanges();

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

if (!GraphicsDevice.IsFullScreen)
   GraphicsDevice.ToggleFullScreen();
于 2009-04-06T07:08:14.123 回答
-1

你应该看看这个,http://forums.xna.com/forums/p/1031/107718.aspx

于 2009-07-27T07:45:06.817 回答
-1

此解决方案适用于 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();
于 2010-02-05T14:16:51.543 回答