Okay, I am trying to generate a tile map with this code. However, I keep on getting an array index out of bounds. So, how this works is that for the "path" I add in a text file. It holds different numbers each representing its own tile texture. The first 2 numbers of the text file is the width and height of it in which we use. What this for loop is doing is assigning each array of tiles[x][y] to a tile in a position where it belongs. Here is the text file I am using:
15 5
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
(there is not extra spaces between the lines idk why it did that)
if there is anything i need to clear up let me know
String textFile = TextUtility.loadTextAsString(path);
String[] tileValue = textFile.split("\\s+");
width = TextUtility.parseToInt(tileValue[0]);
height = TextUtility.parseToInt(tileValue[1]);
System.out.println(width+" "+height + " " + tileValue.length);
tiles = new int[width][height];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
tiles[x][y] = TextUtility.parseToInt(tileValue[(x+y*(width))+2]);
System.out.print(""+ tileValue[(x+ y*(width))+2]);
}
}
You're input height is 5 but you only have 4 lines of tiles.