0

I'm coming back to make a game with XNA, but I got an issue. When I use IsFullScreen from my GraphicsDeviceManager and put it to true in the Game contructor, my game doesn't go to full screen, it's staying windowed.

I looked for the value of IsFullScreen, and while I'm in the Game constructor its value is true, but when I look at the value in the Update or Draw the valoue is false.

I tried to put the value to true when I press F, but nothing changed. I also tried to use ToggleFullScreen, the value of IsFullScreen is well changed but nothing is happening. I tried to set the PreferredBackBuffer width and height, then I need to use ApplyChanges and it put IsFullScreen to false every time I call it. Even if it changes the window size, it's not in full screen, so not what I want.

Here is my code, tell me if you see anything, any advice is welcome.

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace MyGames
{
  /// <summary>
  /// This is the main type for your game
  /// </summary>
  public class SpaceInvader : Game
  {
    private readonly GraphicsDeviceManager graphics_;
    private KeyboardState oldKeyboardState_;
    private KeyboardState newKeyboardState_;
    private SpriteBatch spriteBatch_;
    private Ship playerShip_;

    public SpaceInvader()
    {
      graphics_ = new GraphicsDeviceManager(this);
      Content.RootDirectory = "Content";
      // Set device frame rate to 60 fps.
      TargetElapsedTime = TimeSpan.FromSeconds(1 / 60.0);
      graphics_.PreferredBackBufferWidth = 480;
      graphics_.PreferredBackBufferHeight = 268;
    }

    protected override void Initialize()
    {
      playerShip_ = new Ship(new Vector2(Window.ClientBounds.Width / 2, Window.ClientBounds.Height - 150), new Vector2(10,10));
      base.Initialize();
    }

    protected override void LoadContent()
    {
      // Create a new SpriteBatch, which can be used to draw textures.
      spriteBatch_ = new SpriteBatch(GraphicsDevice);
      playerShip_.LoadContent(Content);
    }

    protected override void UnloadContent()
    {
      // TODO: Unload any non ContentManager content here
    }

    protected override void Update(GameTime gameTime)
    {
      newKeyboardState_ = Keyboard.GetState();
      // Allows the game to exit
      if (newKeyboardState_.IsKeyDown(Keys.Escape))
        Exit();

      // TODO: Add your update logic here
      playerShip_.Update(Window, newKeyboardState_, oldKeyboardState_);

      base.Update(gameTime);
    }

    protected override void Draw(GameTime gameTime)
    {
      if (oldKeyboardState_.IsKeyDown(Keys.F) && newKeyboardState_.IsKeyUp(Keys.F))
        graphics_.ToggleFullScreen();
      graphics_.GraphicsDevice.Clear(Color.CornflowerBlue);
      //set rendering back to the back buffer

      // Draw the sprite.
      spriteBatch_.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
      playerShip_.Draw(spriteBatch_);
      spriteBatch_.End();

      base.Draw(gameTime);
      oldKeyboardState_ = newKeyboardState_;
    }
  }
}

I'm using Windows 7, and VisualStudio Ultimate 2012.

EDIT1: I just tried with VisualStudio 2010 and it works perfectly.

I've also noticed another issue I had before, in the Program.cs I cannot use:

 using (SpaceInvader game = new SpaceInvader())
 {
   game.Run();
 }

I need to use instead:

SpaceInvader game = new SpaceInvader();
game.Run();

I don't know if it's changing something but it will throw me the exception NullReferenceException was unhandled on the second brace.

EDIT2: I read on the download page of XNA that it allows me to use VisualStudio 2010 but it is not talking about VisualStudio 2012. And after reading these kind of pages I guess it is normal that it's not working well because I didn't do anything of that sort to install XNA.

I guess this is an issue due to VS2012.

Community
  • 1
  • 1
  • I tried compiling your code, and it worked fine. You must be not showing something relevant. – davidsbro Mar 24 '14 at 16:19
  • Okay, that's strange i think, I just tried with VS2010 and it works perfectly. –  Mar 24 '14 at 17:12
  • If you want to use XNA with Visual Studio 2012 I recommend using this app to setup the dependencies properly. http://what-ev.net/2014/02/19/the-xna-enabler-app-xna-in-visual-studio-2012-2013/ – Loothelion Mar 24 '14 at 18:49
  • Another posibility is save the user preferences in a settings file and load it on startup. Many games require a restart to change graphics settings, nothing to be shamed about. – Madmenyo Mar 31 '14 at 17:12
  • Thanks, and yes I think you are right, but still the goal was to understand what was going on under XNA. –  Apr 03 '14 at 21:21

3 Answers3

0

Haha. Small mistake, you need to add: this.graphics.ApplyChanges();. I did the same thing once. Understand that you need to do that every time you want to change something, there will be no changes until that is called.

Ryan Foy
  • 322
  • 6
  • 19
  • euh, no, I said I tried this, and it put `graphics.IsFullScreen` to false everytime it is called. So it won't get in full screen then. I really think there's just an issue with VS2012 and I need to use VS2010 or use some other apps like Loothelion said in comment of my post or do some tricks like it is said in the link I posted. –  Mar 25 '14 at 16:49
0

I am going to close the subject as answered cause as I said to use XNA you need to use VS2010.

I read on the download page of XNA that it allows me to use VisualStudio 2010 but it is not talking about VisualStudio 2012. And after reading these kind of pages I guess it is normal that it's not working well because I didn't do anything of that sort to install XNA.

I guess this is an issue due to VS2012.

-4

Try the code below instead of toggling a bool:

isFullscreen() = true;
Code Maverick
  • 20,171
  • 12
  • 62
  • 114
m0ddixx
  • 43
  • 4