I'm not very experienced when it comes to using .txt files in XNA and therefore i need some help.
I'm tring to make a Tile Engine read and put information depending on what number is in the .txt document. It looks something like this:
1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 etc
Now, this document contains 50 characters in X (25 without [ , ]) and has 15 lines in Y. The problem is that it only reads the first line in Y and not the other 14 remaining ones in Y, which is causing it to crash.
Here is the code:
public void LoadMap(string MapName)
{
using (StreamReader streamReader = new StreamReader("Content/" + MapName + ".txt"))
{
do
{
string line = streamReader.ReadLine();
string[] numbers = line.Split(',');
int temp = 0;
for (int y = 0; y < loopY; y++)
{
for (int x = 0; x < loopX; x++)
{
Blocks[y, x] = new Block();
//Crashes here when temp reaches 25
if (int.Parse(numbers[temp]) == 1)
Blocks[y, x].color = Color.Blue;
else if (int.Parse(numbers[temp]) == 2)
Blocks[y, x].color = Color.Violet;
else
Blocks[y, x].color = Color.White;
temp++;
}
}
} while (!streamReader.EndOfStream);
}
}
numbers[]? What's the exception you're seeing? - Bill