Hi,
I'm experimenting with using a tile based system for a game, the colour of the tiles are based off the int which is found when converting a char array storing the integer found in a text file. 0 is a black tile, 1 is a green tile and 2 is a new line.
This is the code which places the tiles:
Code:
public void createMap() {
for (int y = 0; y <= 5; y++ )
{
for (int x = 0; int.Parse(readMapArray[tileIndex].ToString()) < 2; x++ )
{
tileIndex++;
createTile(int.Parse(readMapArray[tileIndex].ToString()));
tilePoint = new Point(tilePoint.X + 32, tilePoint.Y);
}
tileIndex++;
tilePoint = new Point(0, tilePoint.Y + 32);
}
}
I get a "Format exception was unhandelled" error on the line when the second for loop initialises.
I only get the error when i include the second incrementation of tileIndex. however, if i take this out, it only creates the first line of tiles (because it doesn't increment the next index past the value of 2).
This is my code to change the colour of the tile (the createTile):
Can you show us where you initialize readMapArray?
Best Regards,
BioPhysEngr http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
I solved it, I was using a text file which was converted into a char array and then converted that into an integer in the loops posted above. Instead I just converted the text file straight from string to Int array.
I have no idea why I didn't do this in the first place but for the sake of really wanting to know why it didn't work anyway,
This was my code for converting the text file:
Code:
//reads the text file and
public void readMap(String map)
{
srMapReader = new StreamReader("Maps//"+map+".txt");//gets map
string readMap = srMapReader.ReadToEnd();//reads
readMapArray = readMap.ToCharArray();
srMapReader.Close();//ends stream
}
BioPhysEngr http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
Bookmarks