8

i'm making a simple game to show as final project. It will display a .bmp frame within the window and i have no intention of resizing the window while the game is running so i want to fix the window's size. The issue is that when i run the project created by choosing monogame game in visual studio 2012 it start in full screen mode. I tried to fix it with this code:

_graphics.IsFullScreen = false;
_graphics.PreferredBackBufferWidth = 640;
_graphics.PreferredBackBufferHeight = 480;
_graphics.Applychanges();

I've put it in the constructor of the main game class and in the initialize function but it does nothing. i'm using monogame 3.0.

Mario Gil
  • 493
  • 1
  • 5
  • 14
  • This appears to be a bug in MonoGame. I'm fairly certain the code you posted should work. I found this discussion https://github.com/mono/MonoGame/issues/1762 and it appears as a dirty workaround you can call _graphics.CreateDevice() BEFORE the code above. – craftworkgames Nov 25 '13 at 00:31
  • 1
    Thanks for your help, still i can't set a fixed window but now resolution of fullscreen mode changed, this is in visual studio 2012. I tested the same code in visual studio 2010 and it works perfectly i'm new to monogame and a big rookie in programming so i don't know what's really going on, i'm going to stick with VS 2010 this time. – Mario Gil Nov 25 '13 at 22:57

2 Answers2

3

Try putting it in the Initialize method instead of the constructor.

Should do the trick:

protected override void Initialize()
{
    _graphics.IsFullScreen = false;
    _graphics.PreferredBackBufferWidth = 640;
    _graphics.PreferredBackBufferHeight = 480;
    _graphics.Applychanges();

    base.Initialize();
}
distractedhamster
  • 689
  • 2
  • 8
  • 22
1

The best way to resize the window is using the "GraphicsDeviceManager". Set up the graphics like that

private GraphicsDeviceManager _graphics;

then write your code into the initialize method (pay attention to capital letters):

 protected override void Initialize()
    {
        _graphics.PreferredBackBufferWidth = 640;
        _graphics.PreferredBackBufferHeight = 480;
        _graphics.ApplyChanges();

        base.Initialize();
    }
Cyprien
  • 11
  • 4