• Advertisement
Sign in to follow this  

Rotating Images With Angles On KeyPresses

This topic is 1984 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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);
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement