31
Graphics / Sprite Movement on Single MouseClick
« on: January 17, 2012, 10:48:53 pm »
I got it to work now thanks to everyone. Just one little thing lol. The player continuously follows the cursor, even though everything is now within the if statement, it doesnt wait for an action from the mouse.
Code: [Select]
if (App.GetInput().IsMouseButtonDown(sf::Mouse::Left));
{
Clock1.Reset();
float NewX = App.GetInput().GetMouseX();
float NewY = App.GetInput().GetMouseY();
sf::Vector2f Origin = PlayerObj.GetPosition();
sf::Vector2f Destination = sf::Vector2f (NewX, NewY);
sf::Vector2f Direction = Destination - Origin;
float Distance = sqrt( (Destination.x - Origin.x) * (Destination.x - Origin.x) + (Destination.y - Origin.y) * (Destination.y - Origin.y) );
Direction /= Distance;
float Speed = .5f;
PlayerObj.SetPosition(Origin + Direction * Speed);
}