I just cannot fix this problem about rotating sprites around the mouse. The formula seems fine to me and it is similar to others I have googled. I just cannot figure out why it is behaveing in such a weird way.
void Animation::checkRotation(int x, int y, sf::Sprite& backSprite, int px, int py)
{
yOffset = y - py;
xOffset = x - px;
backSprite.SetCenter(px +200, py + 400);
a = (atan2(yOffset, xOffset)) * 180 / 3.141592;
backSprite.SetRotation( a );
}
where x and y are the mouse coordinates and px and py the sprite image coordinates. I thought that maybe when the sprite rotates, the x and the y also change dynamically, in that case, would there be a solution?
I just need a way to get my image looking at the mouse cursor. The sprite.getCenter() doesn't work so I cannot get the center of the image coordinates. Any ideas?
P.S: I am using SFML 1.6