PointerInfo a = MouseInfo.getPointerInfo();
Point b = a.getLocation();
double mouseX = b.getX();
double mouseY = b.getY();
int centerX = playerWidth / 2;
int centerY = playerHeight / 2;
double angle = Math.atan2(centerY - mouseY, centerX - mouseX) - Math.PI / 2;
Graphics2D g2d = (Graphics2D)g;
try{
g2d.rotate(angle, centerY, centerX);
g2d.drawImage(player1, (int)x, (int)y, null );
}catch(Exception ex){
ex.printStackTrace();
}
这会旋转图像,但它不是按照图像的中心旋转,而是在左上角进行旋转,我希望它在我绘制的图像中心旋转。 我已经搜索了很长时间的互联网,无法找到解决方案,所以有人可以帮助我吗?