I made a simple test in xna 2D sprite and tried to move it with mouse, it works but if I move it a bit fast the sprite is lost on the way, I keep the left button pressed and when I'm back to the sprite the drag continues...
I wonder why if I moved a bit fast I lose my sprite???
Here is my move logic :
MouseState ms = Mouse.GetState();
if ((ButtonState.Pressed == Mouse.GetState().LeftButton) && myBall.RectObject.Intersects(new Rectangle(ms.X, ms.Y, 0, 0)))
{
myBall.RectObject = new Rectangle(ms.X - myBall.RectObject.Width / 2, ms.Y - myBall.RectObject.Height / 2, myBall.RectObject.Width, myBall.RectObject.Height);
}
I suggest handling it like this:
if the mouse is left-clicked on the ball (Using the if statement in the OP), then mark the ball as being dragged (A simple 'bool dragged;' on the object)
If the mouse is not left clicked at any time regardless of location, mark the ball as not being dragged.
If the ball is being dragged, jump to the mouse position (Using the code within the if block in the OP)
(All in the same function you are already using)
Edit: here's some sample code in case I didn't explain clearly
MouseState ms = Mouse.GetState();
if ((ButtonState.Pressed == Mouse.GetState().LeftButton))
{
if (myBall.RectObject.Intersects(new Rectangle(ms.X, ms.Y, 0, 0)))
{
myball.dragged = true;
}
}
else
{
myball.dragged = false;
}
if (myball.dragged)
{
myBall.RectObject = new Rectangle(ms.X - myBall.RectObject.Width / 2, ms.Y - myBall.RectObject.Height / 2, myBall.RectObject.Width, myBall.RectObject.Height);
}