我有ImageIcon face
,我不知道如何使用命令rotate
来旋转玩家脸部。我知道旋转是针对点0, 0
。但如何使用旋转只有一个项目?
我的代码是:
int size = 40;
int angle = getAngle(); // in degree...
g2.rotate(Math.toRadians((double)angle); //????????
g2.drawImage(face.getImage(), size * col, size * row, null);
有人可以告诉我吗?
谢谢。
答案 0 :(得分:1)
您可以使用Rotated Icon类在绘制图标时更改图标的旋转度。 RotatedIcon
类可用于在使用Icons的任何组件上旋转Icon。
您还可以使用以下代码在面板上自定义绘制RotatedIcon
:
1)您可以创建类似以下内容的图标:
RotatedIcon face = new RotatedIcon(new ImageIcon(...), 0);
2)然后在您的绘画代码中使用:
face.paintIcon(this, g2, x, y); // determine you x/y location
3)当您想要旋转您使用的图标时:
face.setDegrees(...);
panel.repaint(); // then panel where you do the custom painting