initially image placed (0,0)th position and where ever i touch that is end position.

Now i got Start Position(0,0) and End Position(200,200).

i want to move start to end vector using angle.

If anyone now the ans please tell me.

  • \$\begingroup\$ -1 It is not clear at all what you're asking. Do you want to draw a line or determine the angle of the vector or something else? \$\endgroup\$ Apr 17 '12 at 5:19
  • \$\begingroup\$ i want to move image using two vector points/rectangle points. \$\endgroup\$ Apr 17 '12 at 5:22
  • \$\begingroup\$ So what do the two points have to do with it? Are you resizing the image, are you moving it to point B, or what? \$\endgroup\$ Apr 17 '12 at 5:23
  • \$\begingroup\$ i want to move image A position to B position with angle \$\endgroup\$ Apr 17 '12 at 5:29
  • 2
    \$\begingroup\$ Possible duplicate: gamedev.stackexchange.com/questions/22952/… \$\endgroup\$
    – Roy T.
    Apr 17 '12 at 5:52

You need to find the delta between your two vectors and just move the sprite along that new vector.

Vector2 startPos = new Vector2(0,0);
Vector2 endPos = new Vector2(100,200);

Vector2 delta = endPos - startPos;

//see if he is at the target. Very rarely will it be Vector2.Zero, so subtract 3 to get you close. If you don't do this your sprite can bounce.
if ((delta.X > -3 && delta.X < 3)
  && (delta.Y > -3 && delta.Y < 3))
    sprite.Moving= false;

    delta.Normalize() //you want to normalize the vector. Otherwise he will move faster diagnoally

    sprite.Position += delta *5f;  //5f is a random speed I chose. The higher this number, the faster he will move

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.