I'm currently making a remake of a game for an assessment at school, so forgive me if I have done anything wrong. I have tried to make a foreach loop so that it draws the amount of enemyplanes to the screen. I have made 1 loop in the update game time. The error is "NullReferenceException was Unhandled" and below that is "Object Reference not set to an instance of the object". This same code worked in another "practive" game we made in class, so I'm not sure what I'm doing wrong.
foreach (EnemyPlane ball in enemyplaneObjects)
{
ball.Update();
}
and another in the draw update.
foreach (EnemyPlane ball in enemyplaneObjects)
{
ball.Update();
}
and another thing to consider is that both "ball" reference's value's are null and are not declared in the array or in the spritebatch.
This is the spritebatch.
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D truckTexture;
Vector2 truckPosition;
Texture2D planeTexture;
Vector2 planePosition;
Texture2D backgroundTexture;
Vector2 backgroundPosition;
Texture2D enemyplaneTexture;
Vector2 enemyplanePosition;
int enemyplaneCount = 5;
Texture2D personTexture;
Vector2 personPosition;
Parachute personObject;
Vector2 spriteVelocity = new Vector2(0.5f, 0f);
Random rand = new Random();
EnemyPlane[] enemyplaneObjects;
and this is the array.
enemyplaneObjects = new EnemyPlane[enemyplaneCount];
for (int index = 0 ; index < enemyplaneCount; index++)
{
byte r = (byte)rand.Next(64, 256); //Red Value
byte g = (byte)rand.Next(64, 256); //Green Value
byte b = (byte)rand.Next(64, 256); //Blue Value
byte a = (byte)rand.Next(64, 256); //Alpha Value
Color tempColor = new Color(r, g, b, a);
enemyplaneObjects[0] = new EnemyPlane(EnemyPlane.Texture, new Vector2(rand.Next(2, 100), rand.Next(2, 100)), new Vector2(rand.Next(-2, 20), rand.Next(-2, 20)), tempColor);
}
Thanks in advance.