0

I have a problem in Java. I'm trying to create a 2D shape and rotate it but if I try to rotate it with the Graphics2D's rotate method, the whole canvas gets rotated.

I would like to only rotate a specific shape, not the whole canvas.

My current render method looks like this:

@Override
public void render(Graphics g)
{
    Graphics2D g2d = (Graphics2D) g;
    g2d.setColor(super.color);
    g2d.rotate(Math.toRadians(5));
    g2d.fillRect(100, 100, 50, 50);

}

How should I go about doing this?

Bun
  • 128
  • 1
  • 7
  • Possible duplicate of [Rotate a Java Graphics2D Rectangle?](http://stackoverflow.com/questions/7517688/rotate-a-java-graphics2d-rectangle) – ArcticLord Oct 06 '16 at 10:00
  • Doesn't the post you linked have an answer that points to rotating the whole Graphics2D object itself or am I missing something? – Bun Oct 06 '16 at 10:34
  • Look at the second answer, not the accepted one. `create` and `dispose` are your friends – ArcticLord Oct 06 '16 at 10:39
  • Nice! Using the Path class helped a lot actually. – Bun Oct 06 '16 at 11:04

0 Answers0