This content has been marked as final. Show 3 replies
Is the speed fixed? If not, you just had to change the x and y position constantly, but I guess you wouldn't have asked then.
So when it's fixed, you need to know the distance from start to end point. As you know both points, you can use
distance = Math.sqrt( Math.pow(startPoint._x - endPoint._x, 2) + Math.pow(startPoint._y - endPoint._y, 2) );
this gets the length of the line between those points in pixels.
Then you can get the time it will take to go that distance in the given speed:
time = distance / speed;
Now if the speed is something like 50 pixels per second, the time is also in seconds, and you will get something like 5 seconds. Now take the animation speed (e.g. the framerate, if you animate with onEnterFrame), and get the number of animation steps it will take to reach the end:
steps = time * animation_speed
Finally get the total distances for x and y, which is endPoint.(x | y) - startPoint.(x | y), and divide those by the steps number to get the distance for each step:
stepX = (endPoint._x - startPoint._x) / steps;
stepY = (endPoint._y - startPoint._y) / steps;
Now you have the distance for each animation step and can use them in the animation to move the ball with the given speed.
"information not shared is lost"
don't know who said that, but it's a good statement... and true.