Jump to content

  • Log In with Google      Sign In   
  • Create Account


Rotating Images With Angles On KeyPresses


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Bench3   Members   -  Reputation: 126

Like
0Likes
Like

Posted 16 August 2012 - 09:32 AM

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

Sponsor:

#2 CryoGenesis   Members   -  Reputation: 484

Like
-1Likes
Like

Posted 16 August 2012 - 11:12 AM

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);
}




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS