So, I have a list of vectors, when I put a new vector in it it works perfectly, but If I try to access an index of List of Vectors and put a vector in it, I get this error "Object reference not set to an instance of an object." The code is almost the same for each List:
class GameMap
{
MouseHandler mouseHandler;
TileSet tileSet;
List<Vector2>[] tiles;
List<Vector2> tile;
public GameMap(ContentManager Content)
{
mouseHandler = new MouseHandler();
tileSet = new TileSet(Content);
}
public void Initialize()
{
tiles = new List<Vector2>[tileSet.tiles]; //What am I doing wrong here?
tile = new List<Vector2>();
}
public void MapEditor()
{
mouseHandler.MouseUpdate();
if (mouseHandler.LeftButton == true)
{
tiles[0].Add(mouseHandler.MousePosition); //The error comes out here.
tile.Add(mouseHandler.MousePosition);
}
}
public void Draw(SpriteBatch spriteBatch)
{
for (int i = 0; i < tileSet.tiles; i++)
{
tileSet.TiledTexture(spriteBatch, tiles[i], i);
tileSet.TiledTexture(spriteBatch, tile, i);
}
}
}
The "Tiles" with multiples Lists of vectors isn't working, what am I doing wrong?