tags:

views:

45

answers:

1

I have the ball in the very right bottom side. When I click somewhere, I want to be able to figure out the direction I clicked and once the user starts to drag, I will calculate the distance. Once the user lets go of the mouse, I want to give the ball some velocity and have it move towards the direction it was first clicked.

I don't know the formulas to compute these things. Any help with explanation is greatly appreciated.

Thanks.

+2  A: 

You can check the first mouse down Mouse.GetState() (I think) and save it to a variable. Then check, if the mousedown-state is still given (do this in the Update() function), if not, this will be your destination point. Now you have a starting point and destination point, so you can move your ball in the update-method through the destination point. I hope, the explanation is clear :)

cevik
If I moved it towards the destination point, wouldn't it just move to that position in a blink? and not do a smooth transition?
RoR
You can do your smooth transition if you add or remove just one pixel from the startingpostion (X and Y) every update loop till you get the ball to the destination position.
cevik