Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
-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? –  Jonathan Hobbs Apr 17 '12 at 5:19
    
i want to move image using two vector points/rectangle points. –  Ramachandran Apr 17 '12 at 5:22
    
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? –  Jonathan Hobbs Apr 17 '12 at 5:23
    
i want to move image A position to B position with angle –  Ramachandran Apr 17 '12 at 5:29
2  
Possible duplicate: gamedev.stackexchange.com/questions/22952/… –  Roy T. Apr 17 '12 at 5:52
show 3 more comments

1 Answer

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;
}

if(sprite.Moving)
{
    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
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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