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.