Jak ustawić rozmiar okna / ekranu w xna?

Jak mogę dostosować rozmiar okna w XNA.

Domyślnie zaczyna się w rozdzielczości 800x600.

Author: Alex B, 2009-04-06

4 answers

Od XNA 4.0 ta właściwość znajduje się teraz na GraphicsDeviceManager. Ie. ten kod trafiłby do konstruktora Twojej gry.

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();
 70
Author: James,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-04-21 20:24:55

Dowiedziałem się, że trzeba ustawić

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

Kiedy robisz to w konstruktorze klasy gry, to działa, ale kiedy próbujesz zrobić to poza konstruktorem, musisz również wywołać

GraphicsDevice.ApplyChanges();

Ponadto, aby mieć Pełny ekran (który nie działa poprawnie podczas debugowania), możesz użyć

if (!GraphicsDevice.IsFullScreen)
   GraphicsDevice.ToggleFullScreen();
 58
Author: pinckerman,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-11-25 15:06:56
 -1
Author: Nikwin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-07-27 07:45:06

To rozwiązanie działa w XNA 3.0. Po prostu umieść go w konstruktorze obiektu gry:

// 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();
 -1
Author: jabs,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-11-25 15:07:13