I'm trying to make a map using a text file, but it only does the first line / column and not the rest.
I know the problem is in getTileImage
.
public class TileManger {
GamePanel gp;
Tile [] tile;
int mapTileNum [] [];
public TileManger (GamePanel gp) {
this.gp = gp;
tile = new Tile [10];
mapTileNum = new int [gp.maxScreencol] [gp.maxScreenrow];
getTileImage ();
loadMap();
};
public void getTileImage() {
try {
tile[0] = new Tile();
tile[0] .image = ImageIO.read( getClass ().getResource("/Tiles/grass.png") );
tile[1] = new Tile();
tile[1] .image = ImageIO.read( getClass ().getResource("/Tiles/wall.png") );
tile[2] = new Tile();
tile[2] .image = ImageIO.read( getClass ().getResource("/Tiles/water.png") );
}catch (IOException e) {
e.printStackTrace();
}
}
public void loadMap () {
try {
InputStream is = getClass ().getResourceAsStream("/maps/Map_02.txt");
BufferedReader br = new BufferedReader (new InputStreamReader(is));
int col = 0;
int row = 0;
while(col < gp.maxScreencol && row < gp.maxScreenrow) {
String line = br.readLine();{
String numbers[] = line.split(" ");
int num = Integer.parseInt(numbers[col]);
mapTileNum[col] [row] = num;
col++;
}
if(col == gp.maxScreencol) {
col = 0;
row++;
}
}
br.close();
}catch (Exception e) {
}
}
public void draw (Graphics2D g2) {
int col = 0;
int row = 0;
int x = 0;
int y = 0;
while (col < gp.maxScreencol && row < gp.maxScreenrow) {
int tileNum = mapTileNum [col] [row];
g2.drawImage(tile[tileNum].image, x, y, gp.tilesize, gp.tilesize, null);
col++;
x += gp.tilesize;
if (col == gp.maxScreencol) {
col = 0;
x = 0;
row++;
y +=gp.tilesize;
}
}
}
}
Map_02.txt
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 2 2 2 2 2 2 0 0 0 0 1
1 0 0 0 0 2 2 2 2 2 2 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
getTileImage
? Do you get an exception when you run it? If so, be sure to edit your question to include the full text of the exception, or whatever other evidence you've collected in your debugging so far. \$\endgroup\$