I’ve been experimenting with alternating between windowed and full-screen when I noticed something I don’t understand. I’ve set the window dimensions to 640x480, but (in windowed mode) when it’s displayed on screen its 800x480. The Window.ClientBounds says the width is 640. If I get the OpenTK native window, it says it’s width is also 640.
Basically, I’m trying to center the window on screen, and because its width is reading 640 instead of 800, my calculations are getting messed up.
I do this width/height stuff right after base.Initialize()
Thanks in advance,
UPDATE: At the first call to Update(…), I see the Window.Width is now 800. Ok, so somewhere after Initialize() and before Update(), the window width is being resized to 800. So, at what point should I be setting the dimensions if not during Initialize()?
Glad you found a solution. Not a solution for me unfortunately. base.Initialise is what loads the content and for me that takes quite a while and is why I put up a splash screen. I was hoping to fix this in the game constructor but graphicsdevice is null then and calling applychanges does not create one either. Tried creating a new viewport and applychanges in my intiailse before base.initialise is called but I see no change in the initial window displayed, in other words it’s still not set to the preferred size.
@procd Your initialize function should be used to set properties for devices and any components you are using, but you should be loading all your game’s content in the LoadContent() functions.
A splash screen is a great idea if you have a lot of content, but I strongly suggest that you build a system that is similar to the game state manager example from microsoft. This allows you to split up the content you use across different screens i.e. don’t load gameplay content if you are only showing a menu.
If you study the code supplied in that example, you can easily create a very efficient system in monogame.
Your graphics device will be null until base.initialize() is called.
@eric914 I’m going to try and see if I can reproduce your problem. Just so you know, you don’t have to call graphics.ApplyChanges() in initialize() since that is where the GraphicsDeviceManager is instantiated. ApplyChanges() is meant for use while the game is running, during update() for instance, where it will need to be reinitialized
Thanks for the reply. I do use the initialise function for setting up properties and loadcontent for loading the content, but cannot split content and the content loading can take quite a long time so I display a splash screen. It’s annoying that the initial windows in Windows OpenGL seems to be outside the control of the program and so drawing a texture to it with the preferred backbuffer size ends up with a offcentred and miscaled image. I’ve just been trying out solutions to similar problems but so far none have worked and so it seems that you cannot create a suitable splash screen while content loads in a Windows OpenGL environment. (DirectX works fine)