Rotating Images With Angles On KeyPresses

Started by
0 comments, last by CryoGenesis 11 years, 8 months ago
Hi, I was wondering how I could rotate an image when I press a key. For example, if I pressed D it would rotate right and A left. I know how to set up keyListeners but not sure about the rotation.
I then wondered about how I would go about getting something to face a direction. So if I pressed G, the image would turn to face a certain angle?
Thanks in advance!
~Ben
Advertisement
Your best bet is to use a class called AffineTransform. To rotate an image:
public void paint(Graphics g){
Graphics2D g2d = (Graphics2D) g;
Image derp;
//Get the image
AffineTransform form = new AffineTransform();
form.rotate(angle); //Cant really remember this part. Google how to do it?
g2d.setTransform(form);
}

This topic is closed to new replies.

Advertisement