So When I run my game the window opens and is all white inside, and I have to close it
with taskmgr.exe. I get no errors at all, here is my code:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace Game2
{
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Player pla;
bullet[] b;
KeyboardState oldStateShoot;
int x_b = 350;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
graphics.PreferredBackBufferHeight = 800;
graphics.PreferredBackBufferWidth = 900;
}
protected override void Initialize()
{
oldStateShoot = Keyboard.GetState();
b = new bullet[100];
base.Initialize();
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
pla = new Player(Content.Load<Texture2D>("pla"), new Vector2(350, 700));
for (int i = 0; i < 100; i++)
{
b[i] = new bullet(Content.Load<Texture2D>("b"), new Vector2(x_b, 300));
x_b += 10;
}
}
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
pla.Update();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
pla.Draw(spriteBatch);
for (int i = 0; i < 100;)
{
KeyboardState newStateShoot = Keyboard.GetState();
if (newStateShoot.IsKeyDown(Keys.Space) && oldStateShoot.IsKeyUp(Keys.Space))
{
b[i].Draw(spriteBatch);
i++;
}
oldStateShoot = newStateShoot;
}
spriteBatch.End();
base.Draw(gameTime);
}
}
}