ok, Im working on creating the SimpleGame in chapter 11. Right now I just finished the EnemyManager.cs and put the appropriate code it my Game1.cs to make it all work, but when I compile and run it. The mainmenu starts and then I press enter to start the actual game but it pops up with this warning:
NullReferanceException was unhandled
Object reference not set to an instance of an object.
"i < enemies.Length;"
when refering to this part in my code:
public override void Update(GameTime gameTime)
{
float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
for (int i=0; i < enemies.Length; i++)
{
Enemy enemy = enemies;
if (enemy.Active)
{
enemy.Position += (enemy.Velocity * elapsed);
}
}
base.Update(gameTime);
}
public override void Draw(GameTime gameTime)
{
for (int i = 0; i < enemies.Length; i++)
{
Enemy enemy = enemies;
if (enemy.Active)
{
cam.Draw(gameTime, "robot", spriteBatch, enemy.Position);
}
}
base.Draw(gameTime);
}
I have seriously tride everything... I dont know why it wont run that part of the code, the cd has the samethiing written and I cant find any other discrepancies in my code that would make it do something like this?