Jump to content

View more

Image of the Day

WIP title screen for #DeathOfAPartisan #screenshotsaturday #gamedev https://t.co/qJNhfZCvd4
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Rotating Images With Angles On KeyPresses

4: Adsense

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   

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

#2 CryoGenesis   Members   

528
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.