Reputation: 59273
Here is an example of drawing the left leg of my character:
g2d.fillRect(pX + (headW - bodyW)/2, pY + headH + bodyH, legW, legH); //left leg
I know how to rotate images with AffineTransform
s, like this:
AffineTransform tr = g2d.getTransform();
tr.rotate(Math.toRadians(rotAmount));
g2d.drawImage(playerI, tr, null);
How can I rotate this rectangle with an AffineTransform
? I can't do something like:
g2d.rotate(Math.toRadians(rotAmount));
Because that rotates my entire person. How can I rotate only the leg?
Upvotes: 2
Views: 257
Reputation: 59273
Never mind, I found out how.
AffineTransform old = g2d.getTransform();
g2d.rotate(Math.toRadians(lLegRot));
g2d.fillRect(pX + (headW - bodyW)/2, pY + headH + bodyH, legW, legH); //left leg
g2d.setTransform(old);
g2d.rotate(Math.toRadians(rLegRot));
g2d.fillRect(pX + headW - legW - (headW - bodyW)/2, pY + headH + bodyH, legW, legH); //right leg
Newer rotations override older ones while keeping the previously rotated thing intact. To reset rotation just do g2d.setTransform(old);
.
Upvotes: 2
Reputation: 3147
If you decide to use java.awt.geom you can make that with rotate(someAngle) method.
Upvotes: 0