Jump to content
  • Advertisement
Sign in to follow this  
MatejaS

Flip sprite in sprite sheet using Graphics2D

This topic is 1409 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

Hello,

I am using Java Graphics2D to make my game.I haven't worked with it for a while, and I don't know how to do this..

I got a sprite sheet (that has multiple sprites on it). I know how to draw a sprite (using this https://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html#drawImage(java.awt.Image,%20int,%20int,%20int,%20int,%20int,%20int,%20int,%20int,%20java.awt.image.ImageObserver) )... But I need to flip (horizontally or/and vertically) only one sprite on the image, not the whole image.

How can I do this?

Thanks,

MatejaS

Share this post


Link to post
Share on other sites
Advertisement

Use the scaling parameters of the drawImage method to and scale it by a negative amount on the axis you want:

g2.drawImage(image, x, y, -width, height, null);

Share this post


Link to post
Share on other sites

If you want to flip horizontally or flip vertically, just edit the image in the program called "Paint". It can flip horizontal or vertically images and then save as another image file.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!