0

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.

StallMar
  • 31
  • 1
  • 2
  • 7
  • There's not enough context given (by means of code), to actually tell you what goes wrong with it. – πάντα ῥεῖ Dec 14 '14 at 22:59
  • I've updated my post which has everything to do with the scenario. It's not a problem with something going wrong, it's a problem of figuring out how to do something. – StallMar Dec 14 '14 at 23:08
  • You need to rotate the exhaust point around the centerpoint of the playership like this: http://stackoverflow.com/questions/786472/rotate-a-point-by-another-point-in-2d – Rune Andersen Dec 14 '14 at 23:20
  • Thanks for the response but that isn't what I'm looking for. I need the sprite to update it's position with the player ship, not circle around the ship which is what the formula provided in the link would do. – StallMar Dec 14 '14 at 23:40
  • You will want your exhaust to rotate around it's own center and around the ship. – Rune Andersen Dec 15 '14 at 23:04

0 Answers0