int startY = clip.y / maxHeight;
int startY = clip.y / theight;
    public void paint(Graphics g) {        Rectangle clip = g.getClipBounds();        paintBackground(g);        if (tilesets.size() <= 0) {            return;        }        for (int i = 0; i < tilesets.size(); i++) {            TileSet tileset = (TileSet)tilesets.get(i);            if (tileset != null) {                // Draw the tiles                int maxHeight = tileset.getTileHeight();                int twidth = tileset.getTileWidth() + 1;                int theight = tileset.getTileHeight() + 1;                int tilesPerRow = Math.max(1, (getWidth() - 1) / twidth);                int startY = clip.y / maxHeight;                int endY = (clip.y + clip.height) / theight + 1;                int tileAt = tilesPerRow * startY;                for (int y = startY, gy = startY * maxHeight; y < endY && tileAt < tileset.getMaxTileId(); y++) {                    for (int x = 0, gx = 1; x < tilesPerRow; x++) {                        Tile tile = null;                        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 += maxHeight;                }            }        }    }