java slick2d image rotation according to current mouse cursor location

216 views Asked by At
float mouseX = input.getMouseX();
float mouseY = input.getMouseY();

float xDistance = mouseX - imageX;
float yDistance = mouseY - imageY;
double angleToTurn = Math.toDegrees(Math.atan2(yDistance, xDistance));
image.setRotation((float) angleToTurn);

the image is rotating but the mouse's cursor is off the center of the image, it's always on the right side or x coordinate and y coordinates of the image. When I drag the mouse 90 degrees to the right, the image will rotate 90 degrees to the right but the mouse's cursor is out of the center of the image, it's always on the right hand side of the image wherever the rotation occur. Should I make an if statement? Thank you in advance.

0

There are 0 answers