int gy = startY * theight;  for (int y = startY; y < endY && tileAt < tileset.getMaxTileId(); y++) { int gx = 1; for (int x = 0; x < tilesPerRow; x++) { Tile tile; while ((tile = tileset.getTile(tileAt++)) == null) { if (tileAt > tileset.getMaxTileId() || tileAt-1 == 0) { break; } }
for (int y = startY, gy = startY * theight; y < endY && tileAt < tileset.getMaxTileId(); y++) { for (int x = 0, gx = 1; x < tilesPerRow; x++, tileAt++) { Tile tile = (Tile) tilesetMap.get(tileAt);
    public void paint(Graphics g) {        Rectangle clip = g.getClipBounds();        paintBackground(g);        if (tileset != null) {            // Draw the tiles            int twidth = tileset.getTileWidth() + 1;            int theight = tileset.getTileHeight() + 1;            int tilesPerRow = Math.max(1, (getWidth() - 1) / twidth);            int startY = clip.y / theight;            int endY = (clip.y + clip.height) / theight + 1;            int tileAt = tilesPerRow * startY;            int gy = startY * theight;            for (int y = startY; y < endY && tileAt < tileset.getMaxTileId(); y++) {                int gx = 1;                for (int x = 0; x < tilesPerRow; x++) {                    Tile tile;                    while ((tile = tileset.getTile(tileAt++)) == null) {                        if (tileAt > tileset.getMaxTileId() || tileAt-1 == 0) {                            break;                        }                    }                    if (tile != null) {                        tile.drawRaw(g, gx, gy + theight, 1.0);                    }                    gx += twidth;                }                gy += theight;            }        }    }