0

I have ImageIcon face, I don't know how to use command rotate to rotate player face. I know that the rotation is for point 0, 0. But how to use for rotate only one item?

My code is:

int size = 40;
int angle = getAngle(); // in degree...

g2.rotate(Math.toRadians((double)angle); //????????
g2.drawImage(face.getImage(), size * col, size * row, null);

Can anyone advise me?

Thank you.

runDOSrun
  • 10,359
  • 7
  • 47
  • 57
coupraes
  • 21
  • 1
  • 1
  • 3
  • 1
    Please give greater detail to your question. If your problem is that you want to rotate only one thing that you draw, consider creating a copy of the Graphics2D object, and use the copy to rotate and draw the one item. To show you better how to do this, again, please give us more detail about your problem and also create and post a small but simple complete program that illustrates your problem, an [MCVE](http://stackoverflow.com/help/mcve). Please check the link for the details of this very useful tool. – Hovercraft Full Of Eels Jul 11 '15 at 13:52
  • possible duplicate of [Rotate JLabel or ImageIcon on Java Swing](http://stackoverflow.com/questions/4287499/rotate-jlabel-or-imageicon-on-java-swing) – JDrost1818 Jul 11 '15 at 15:05

1 Answers1

1

You can use the Rotated Icon class to change the degrees of rotation of the Icon when painting it. The RotatedIcon class can be used to rotate an Icon on any component that uses Icons.

You can also custom paint the RotatedIcon on a panel using code like the following:

1) You would create the Icon something like:

RotatedIcon face = new RotatedIcon(new ImageIcon(...), 0);

2) Then in your painting code you use:

face.paintIcon(this, g2, x, y); // determine you x/y location

3) When you want to rotate the icon you use:

face.setDegrees(...);
panel.repaint(); // then panel where you do the custom painting
camickr
  • 321,443
  • 19
  • 166
  • 288