So, I made a tile engine so I can draw different parts of a map easily, but for some reason I get a strange lag when I do it.
The tile render code looks as such:
public void drawMap(Graphics g, Image tileImages[]){ int drawDistanceX = 60; int drawDistanceY = 60; if (keyStatus == "DOWN"){ switch(key){ case 100: if (mapX < mapWidth-20){mapX++; break;} case 97: if (mapX > 0){mapX--; break;} } } if (mapWidth > 20){drawDistanceX = 20;}else{drawDistanceX = mapWidth;} if (mapHeight > 15){drawDistanceY = 15;}else{drawDistanceY = mapHeight;} for (int y = 0; y < drawDistanceY;y++){ for (int x = 0; x < drawDistanceX; x++){ if (mapTiles[x+(int)mapX][y+(int)mapY][0] > 0){ g.drawImage(tileImages[mapTiles[x+(int)mapX][y+(int)mapY][0]],x*16,y*16,null); } } } }
Now, I don't think it's the image drawing itself, but I could be wrong. Something this simple really shouldn't bother java as much as it is.