Search code examples
c#windows-8fullscreenmonogame

How do i set a fixed window size in monogame?


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.


Solution

  • 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();
    }