In the below code I have the player ship face in the direction of the mouse position. How exactly would I go about attaching an exhaust / fire animation to the bottom of the ship so that it always stays at the bottom of the ship and rotates with the ship? The origin x, y points of all sprites are centered.
void CMyGame::OnMouseMove(Uint16 x,Uint16 y,Sint16 relx,Sint16 rely,bool bLeft,bool bRight,bool bMiddle)
{
player_rotation = atan2(y - player.GetY(), x - player.GetX()) * (180/3.14159);
if (player_rotation < 0) player_rotation = 360 - (-player_rotation);
player.SetRotation(player_rotation-90);
}
Angle 0 / 360 is when the ship is facing right. 90 is facing up. So it's clockwise starting from the right direction.
When I create an animated fuel / fire sprite, it's placed at this position:
player.GetX(), player.GetY() - player.GetWidth() / 2, fire_texture);
meaning it will be initially placed at the very bottom middle of the player ship, as you'd expect for a spaceship's exhaust. But I need it to rotate with the ship so that if the ship is facing left, the exhaust would have it's position updated to be rotated in the same angle as the ship, meaning the exhaust would be facing left as well - while still being attached to the bottom of the ship.