I was wondering how to rotate a png image. I have tried searching the forums for relevant information, but haven’t been able to figure out the problem yet. Some of the topics I’ve read about using Affine Transform to rotate my images don’t make a whole lot of sense to me.
How am I supposed to use Affine Transform to rotate my sprite? I’ve already tried doing something akin to this:
[quote]Here is one method I use:
Write a draw(Graphics2D) method for the Sprite class.
In the painting method, you can store the current AffineTransfrom of the Graphics2D with
Code:
AffineTransform emptyXform = g2d.getTransform();
for( all the sprites ){
g2d.setTransform(emptyXform);
sprite.draw(g2d)
}
In the draw method of the sprite you can do any transformation necessary on the Graphics2D without wrecking anything. emptyXform simply resets the transform to one which doesn’t do anything (it’s probably just the identity transformation). Simply use
Code:
g2d.rotate(angle, centerX, centerY);
inside the draw() methods of the sprites.
[/quote]
(posted by Ask_Hjorth_Larsen, May 16, 2005)
However, what this ends up doing is rotating everything on the screen, including my sprite, and background image.
Thanks for any help!