i wanna make a sprite move to the mouseclick (like in most strategie games). But i made it only while i press and hold the left mouse button so far. When i change the if-clauses to while loops, the sprite goes immediately to the mouse position. Can someone help me? Is there maybe an easier way to make a sprite move to a specific position by clicking the mouse?
best regards, alex
mCurrentMouseState = Mouse.GetState();
if (mCurrentMouseState.LeftButton == ButtonState.Pressed)
mDestination = new Vector2(mCurrentMouseState.X, mCurrentMouseState.Y);
Vector2 direction = Vector2.Normalize(mDestination - mPosition);
mPosition += direction * (float) gameTime.ElapsedGameTime.TotalSeconds * mSpeed;
if (Vector2.Distance(mPosition, mDestination) < 1)
direction = Vector2.Zero;