Original Post
So I am using a multdimensional array to create a tiled background. It works fine until I try to use a for loop to draw the array, at which point it throws an indexoutofrangeexception.
I declare the variable as:
[source lang="csharp"]Vector2[,] grass = new Vector2[25, 20];[/source]
Then to assign it values I use:
[source lang="csharp"]for (int i = 0; i < 25; i++)
{
for (int j = 0; j < 20; j++)
{
grass[i,j] = new Vector2(i*32,j*32);
}
}[/source]
And to draw it I call:
[source lang="csharp"]for (int i = 0; i < 25; i++)
{
for (int j = 0; i < 20; j++)
{
spriteBatch.Draw(grasstile, grass[i, j], Color.White);
}
}[/source]
It works fine up until the last bit. It gets declared, and the variables are assigned correctly (I manually called each index of the array and it worked fine), yet for some reason the draw throws Indexoutofrangeexception every time it's called.
Maybe I'm just overlooking something simple but I'm stumped right now.
I declare the variable as:
[source lang="csharp"]Vector2[,] grass = new Vector2[25, 20];[/source]
Then to assign it values I use:
[source lang="csharp"]for (int i = 0; i < 25; i++)
{
for (int j = 0; j < 20; j++)
{
grass[i,j] = new Vector2(i*32,j*32);
}
}[/source]
And to draw it I call:
[source lang="csharp"]for (int i = 0; i < 25; i++)
{
for (int j = 0; i < 20; j++)
{
spriteBatch.Draw(grasstile, grass[i, j], Color.White);
}
}[/source]
It works fine up until the last bit. It gets declared, and the variables are assigned correctly (I manually called each index of the array and it worked fine), yet for some reason the draw throws Indexoutofrangeexception every time it's called.
Maybe I'm just overlooking something simple but I'm stumped right now.