Hi people…
Im developing my first game… and i have run into a problem i dont quite know how to solve, which is rotating an image (sounds so easy).
For now i have this… which kind of works…
public void rotateAndDraw(Graphics g, int x, int y, double degreesToRotate) {
double radians = Math.toRadians(degreesToRotate);
Graphics2D g2d = (Graphics2D) g; // Create a Java2D version of g.
double centerx = image.getWidth(null)/2;
double centery = image.getHeight(null)/2;
g2d.translate(centerx,centery); // Translate the center of our coordinates.
g2d.rotate(radians); // Rotate the image by 1 radian.
g2d.drawImage(image, x, y, image.getWidth(null), image.getHeight(null), null);
g2d.rotate(-radians); // Rotate the image by 1 radian.
g2d.translate(-centerx,-centery); // Translate the center of our coordinates.
}
The thing is, i dont actually understande what the translate method does…
And the problem im having is that, although the image IS actually rotating, the pivot point seems to be outside my image.
I though (based on some code i saw on a forum) that the translate method repositions the “pivot” point, but i dont know… i cant seem to get it right…
any help will be greatly appreciated…
thanks in advance
update
i found this link… which is useful…
http://www.glyphic.com/transform/plugin/1intro.html
at least i think i understand what the translate does now.
