How can I rotate a sprite in a Java 2D game, without rotating the entire screen? I want to rotate only the sprite.
I tried doing this:
(g2d is a Graphics2D object);
g2d.rotate(Math.toRadians(30), 50, 50);
g2d.drawImage(image1, 50, 50, this);
g2d.rotate(Math.toRadians(50), 100, 100);
g2d.drawImage(image2, 100, 100, this);
But instead of rotating image1 by 30 degrees, and then rotating image2 by 50 degrees, each rotation affects the entire screen.
Is there a way to rotate only a specific sprite in a game, using the g2d.rotate() method?
If not: I've been told I could use AffineTransform
object, but couldn't find online a tutorial that actually explains how to use this confusing object from the beginning. Could you give me a link or explain to me how to do that with an AffineTransform
object?
I would like the most 'standard' way to do this in a normal 2D game.