I have a ArgumentNullException everytime I try to call the Draw() method of my Projectile class in the Game1.Draw() method.
In Game1.cs Initialize() method:
//PROJECTILES INITIALIZATION
lesProjectiles = new List<Projectile>(20);
for (int i = 0; i < lesProjectiles.Capacity; i++)
{
lesProjectiles.Add(new Projectile(projectileSprite,
new Vector2(playerPosition.X - 15.5f, playerPosition.Y - 20)));
}
This is the Projectile class constructor:
public Projectile(Texture2D texture, Vector2 startPos)
{
this.projectileSprite = texture;
this.projectilePosition = startPos;
}
The -15.5f and -20 values are for placing the projectile at the middle of my spaceship. (Not optimized logic ikr.)
Apart from my whole game logic, let's say I wanna draw the first element of my array. I'm doing that:
In Game1.cs Draw(GameTime gameTime) method:
spriteBatch.Begin();
lesProjectiles[0].Draw(gameTime, spriteBatch);
spriteBatch.End();
And there is the Draw() method from my Projectile class :
public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
{
spriteBatch.Draw(this.projectileSprite, this.projectilePosition,
Color.White);
}
The returned error: System.ArgumentNullException: Value cannot be null. Parameter name: texture
I don't understand why the projectileSprite values of my array elements are null, considering it's done in the initialization method whenever the constructor is called.
Thanks for further help, sorry if my explanations are bad