Mouse Dragging - Page 2
Posted by : webzo on Mar 21, 2008
To do that, double click the frame rate and set it to 30.


The Movie Clips should be moving more smoothly now.
Code Explanation
onClipEvent(load)
{
xSpeed = 0
ySpeed = 0
Two variable for the starting speed on the _x and _y coordinate.
Speed = 40 Speed used for an easing effect, the bigger it is the slower the Movie Clip will move and vise versa.
Stop = 1.13 Variable used to slow the Movie Clip down so it stops in the location of the mouse.
}
onClipEvent(enterFrame)
{
_x += xSpeed
_y += ySpeed
Move the Movie Clip.
xSpeed +=(_root._xmouse - _x) / Speed
ySpeed +=(_root._ymouse - _y) / Speed
Set new speeds using the distance between the current location of the Movie Clip and the position of the mouse divided by the "Speed" variable.
xSpeed /= Stop
ySpeed /= Stop
}
These lines decrease both speeds until it gets in the mouse position.
That's all folks! See you in next tutorial!

no comment
Add comment