So, I am making 2D game in XNA. I was always developing it in windowed mode, but now I tried to do fullscreen. It works ok for most parts but the crucial part fails, and that is when I go out of game (defocus) via Windows key or ALT-TAB and then go back(this is where it crashes).
I use only SpriteBatches.
It returns me no debug info in Visual Studio, but that is because something bad happened in graphics part.
This is Main constructor (originally called Game1)
public Main()
{
status = StatusIgre.GlavniMenu;
Content.RootDirectory = "Content";
gameEndTimer = new Stopwatch();
graphics = new GraphicsDeviceManager(this);
graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
graphics.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
graphics.IsFullScreen = true;
}
}
I also tried this:
protected override void Initialize()
{
//kamera oziroma viewport
camera = new Camera(new Vector2(400,250), GraphicsDevice);
previousState = Keyboard.GetState();
graphics.GraphicsDevice.DeviceLost += new EventHandler<EventArgs>(GraphicsDevice_DeviceLost);
base.Initialize();
}
void GraphicsDevice_DeviceLost(object sender, EventArgs e)
{
PresentationParameters parameters = new PresentationParameters();
parameters.BackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
parameters.BackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
GraphicsDevice.Reset(parameters);
}
Also tried 'throw Exception()' in GraphicsDevice_DeviceLost, but it doesn't seem to show any exception. My guess it doesn't even call this function.
Already searched Google for this, but info on this is poor and mostly for 3D (resetting buffers and such).
So, any suggestions? Truly thanks!