如何在xna中设置窗口/屏幕大小?

如何在xna中设置窗口/屏幕大小?,xna,fullscreen,Xna,Fullscreen,如何在XNA中调整窗口的大小 默认分辨率为800x600。我发现您需要设置 GraphicDevice.PreferredBackBufferHeight=高度; GraphicDevice.PreferredBackBufferWidth=宽度; 当您在游戏类的构造函数中执行此操作时,它会工作,但是当您尝试在构造函数之外执行此操作时,您还需要调用 GraphicsDevice.ApplyChanges(); 此外,您还可以使用 如果(!GraphicsDevice.IsFullScreen

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


默认分辨率为800x600。

我发现您需要设置

GraphicDevice.PreferredBackBufferHeight=高度;
GraphicDevice.PreferredBackBufferWidth=宽度;
当您在游戏类的构造函数中执行此操作时,它会工作,但是当您尝试在构造函数之外执行此操作时,您还需要调用

GraphicsDevice.ApplyChanges();
此外,您还可以使用

如果(!GraphicsDevice.IsFullScreen)
GraphicsDevice.ToggleFullScreen();

您应该看看这一点。

此解决方案适用于XNA3.0。只需将其放入游戏对象的构造函数中:

//将屏幕大小调整为1024 x 768。
IntPtr ptr=this.Window.Handle;
System.Windows.Forms.Form=(System.Windows.Forms.Form)System.Windows.Forms.Control.FromHandle(ptr);
form.Size=新系统图纸尺寸(1024768);
graphics.PreferredBackBufferWidth=1024;
graphics.PreferredBackBufferHeight=768;
graphics.ApplyChanges();

从XNA 4.0开始,现在可以在
图形设备管理器上找到此属性。
这个代码将进入你的游戏的构造器

graphics=新的GraphicsDeviceManager(此);
graphics.IsFullScreen=false;
graphics.PreferredBackBufferHeight=340;
graphics.PreferredBackBufferWidth=480;
//如果在外部更改GraphicsDeviceManager属性
//您的游戏构造函数还调用:
//graphics.ApplyChanges();

此答案有点过时,因此我建议查看下面Fuex的答案。基本上是一样的,但是代码将在不进行任何编辑的情况下编译。Fuex给出的这个答案适用于XNA 4.0。不过,在此之后,您仍然需要执行graphics.ApplyChanges()。