Although it's not possible to easily test this based on the posted code, it's very likely that this is caused by the call to Graphics2D#setTransform
.
Quoting from the JavaDoc:
Overwrites the Transform in the Graphics2D context. WARNING: This method should never be used to apply a new coordinate transform on top of an existing transform because the Graphics2D might already have a transform that is needed for other purposes, such as rendering Swing components or applying a scaling transformation to adjust for the resolution of a printer.
To add a coordinate transform, use the transform, rotate, scale, or shear methods. The setTransform method is intended only for restoring the original Graphics2D transform after rendering, as shown in this example:
// Get the current transform
AffineTransform saveAT = g2.getTransform();
// Perform transformation
g2d.transform(...);
// Render
g2d.draw(...);
// Restore original transform
g2d.setTransform(saveAT);
EDIT: An attempt to apply this pattern to your for-loop, where you called setTransform
, could roughly look like this:
// Store the original transform
AffineTransform oldAT = g2D.getTransform();
for(int x=0;x<(int) l.width;x++){
for(int y=0;y<(int) l.height;y++){
if((x*32+((int)offset.getX())+32)*scale>=0 && (x*32+32+((int)offset.getX())-32)*scale<=getWidth() && (y*32+((int)offset.getY())+32)*scale>=0 && (y*32+((int)offset.getY())-32)*scale<=getHeight()){
Tile t = tiles.getTileById(l.levelData[x][y].getId());
// Apply the rotation to the g2D directly
g2D.rotate((Math.PI/2)*l.levelData[x][y].getRotation(), (x*32+16+((int)offset.getX()))*scale, (y*32+16+((int)offset.getY()))*scale);
g2D.drawImage(t.getImage(), (x*32+((int)offset.getX()))*scale, (y*32+((int)offset.getY()))*scale, (x*32+32+((int)offset.getX()))*scale, (y*32+32+((int)offset.getY()))*scale, 0, 0, 32, 32, null);
// "Undo" the rotation by restoring the original transform
g2D.setTransform(oldAT);
for(OverlayData overlay:l.levelData[x][y].getOverlayData()){
Tile t2= tiles.getTileById(overlay.getId());
int corner = overlay.isCorner()? 1 : 0;
if(t2.hasImage){
g2D.drawImage(t2.getOverlayImage(), (x*32+((int)offset.getX()))*scale, (y*32+((int)offset.getY()))*scale, (x*32+32+((int)offset.getX()))*scale, (y*32+32+((int)offset.getY()))*scale, overlay.getMod()*32, corner*32, overlay.getMod()*32+32, corner*32+32, null);
}
}
}
}
}
// Finally, restore the original transform again
g2D.setTransform(oldAT);
There may be more elegant solutions, though....