I'm using Graphics2D to draw a map on my game.
In the loop it calls this:
for(int i = 0; i < tiles.length; i++){
for(int j = 0; j < tiles[i].length; j++){
if(tiles[i][j]==1){ //GRASS
g2d.drawImage(getImage.getTile("grass.png", 0, 0, ), i* 32, j* 32, null);
}
if(tiles[i][j]==2){ //ROCK
g2d.drawImage(getImage.getTile("rock.png", 0, 0), i* 32, j* 32, null);
}
}
}
And in the method getImage.getTile("grass.png") its just a separate class I made to return a buffered image of the path given.
Now this all works, but it lags like there's no tomorrow. Like I'll press D to go to the right and it takes 3 seconds then the map shifts over in a very laggy fashion! Please help!
Here is the code for the buffered image:
public static BufferedImage getTile(String name, int x, int y){
try{
BufferedImage imageMap;
imageMap = ImageIO.read(getImage.class.getResource("/tiles/"+name));
BufferedImage a = imageMap.getSubimage(x * 32, y * 32 , 32, 32);
return a;
}catch(Exception e){
}
return null;
}
PLEASE NOTE:
Everything DOES work, I'm not here because of errors, just lag!