Original Post
How can I rotate an image in Java? I think I have AffineTransform pretty figured out but I can't figure out how to make a single image rotate without the entire JPanel rotating.
g2d is passed in from the paint method, it is obviously representing the entire contents of the panel. Should every image on the screen have it's own separate instance of graphics so I can only apply the AffineTranformation to it, without applying it to everything else?
Also, all of the coordinates are changing. The force applied by vectors rotate with the everything else. :\
Thanks. None of the search results could clarify this for me.
public void draw(Graphics2D g2d) {
rotate.translate(location.x, location.y);
rotate.rotate(rotation);
rotate.translate(-location.x,-location.y);
g2d.setTransform(rotate);
g2d.drawImage(currentAnimation.getCurrentFrame(), (int) location.x, (int) location.y, null);
}
g2d is passed in from the paint method, it is obviously representing the entire contents of the panel. Should every image on the screen have it's own separate instance of graphics so I can only apply the AffineTranformation to it, without applying it to everything else?
Also, all of the coordinates are changing. The force applied by vectors rotate with the everything else. :\
Thanks. None of the search results could clarify this for me.