Window Centring Fix for MonoGame v3.6

I was debugging a problem I’ve had for a while. Under Windows the running process wouldn’t actually stop once I’d hit ESC even though the Window closed.. After searching I found that it should be fixed, but I was still using MonoGame v3.5.1. I updated to v3.6 which solved it. After upgrading I discovered that the program window now doesn’t auto-centre. They’ve already fixed it for their next build.

 

Here’s the quick workaround I knocked up to see me through until that comes out.

protected override void Initialize()
{
    // Temporary hack to reposition window as auto-centre/center is broken in MonoGame 3.6
    Point WindowSize = new Point(this.Window.ClientBounds.Size.X / 2, this.Window.ClientBounds.Size.Y / 2);
    Point ScreenSize = new Point(graphics.GraphicsDevice.DisplayMode.Width / 2, graphics.GraphicsDevice.DisplayMode.Height / 2);
    this.Window.Position = new Point(ScreenSize.X - WindowSize.X, ScreenSize.Y - WindowSize.Y);
 
    base.Initialize();
}

Leave a Reply

Your email address will not be published. Required fields are marked *