0

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!

Vili Volcini
  • 327
  • 4
  • 16
  • I don't see `graphics.ApplyChanges()` anywhere, that might be the cause. – user1306322 Mar 02 '13 at 22:07
  • You can avoid really going fullscreen by simply by making the game window the size of the screen and centering the window. Also, you could try disabling fullscreen mode if the `IsActive` is false (which means the game window is no longer in focus). – user1306322 Mar 02 '13 at 22:11
  • @user1306322 You don't throw in `ApplyChanges` just willy-nilly. See http://stackoverflow.com/a/11287316/165500 – Andrew Russell Mar 03 '13 at 06:37
  • Ok thanks, gonna crack the problem right now – Vili Volcini Mar 03 '13 at 12:06
  • Didn't fixed the problem, more like avoided it. I didn't go full screen, but still applied full screen (displays) resolution (giving the illusion of full screen). Also removed windows edges. – Vili Volcini Mar 03 '13 at 13:15

0 Answers0