I need to loop through a map that looks like the example bellow and get the width and height of it as well as the number at each point of the file. I then add a tile to that position (multiplied by size) width the parameters (x, y, width, height, id)
. "id
" is the current number in the text file. Here's an example of what the file would look like:
2 0 0 0 0 0 0 0 0 2
2 0 0 0 0 0 0 0 0 2
2 0 0 0 0 0 0 0 0 2
1 1 1 1 1 1 1 1 1 1
I've atempted to add a new Tile at the respective position on the map but mapWidth and mapHeight are returning the actual data in the first position of the file (int this case, 2). How can I return width and height of this text file's data so I can add a tile to the array? Here's the code I've tried:
try {
Tile[][] tiles;
int mapWidth, mapHeight;
int size = 64;
//variables in same scop to save you time :)
FileHandle file = Gdx.files.internal(s);
BufferedReader br = new BufferedReader(file.reader());
mapWidth = Integer.parseInt(br.readLine());
mapHeight = Integer.parseInt(br.readLine());
System.out.println(mapWidth);
int[][] map = new int[mapWidth][mapHeight];
tiles = new Tile[mapWidth][mapHeight];
for(int i = 0; i < tiles.length; i++) {
for(int j = 0; j < tiles[i].length; j++) {
tiles[i][j] = new Tile(i * size, j * size, size, map[j][i]);
}
}
br.close();
} catch(Exception e) { e.printStackTrace(); }