Thursday, 27 September 2012

Mouse following effect in Flash CS6

Recently I found out how to get objects to follow the mouse on the x and y axis at the same time so i can freely move the object around the screen at different speeds.

I made each object a movie clip and named each on Btn1 - Btn5, this smallest being Btn5.

With the following codes on a separate timeline alongside the timeline that had the circles i was able to get the all the objects to follow the mouse.

onEnterFrame = function ()
{
obj._x -= (obj._x - _xmouse)/17
obj._y -= (obj._y - _ymouse)/17
obj2._x -= (obj2._x - _xmouse)/15
obj2._y -= (obj2._y - _ymouse)/15
obj3._x -= (obj3._x - _xmouse)/13
obj3._y -= (obj3._y - _ymouse)/13
obj4._x -= (obj4._x - _xmouse)/11
obj4._y -= (obj4._y - _ymouse)/11
obj5._x -= (obj5._x - _xmouse)/9
obj5._y -= (obj5._y - _ymouse)/9
};

The /number on the end of each line gives a delay in the movement of the object named at the start of the line when it follows the mouse, the bigger the number the slower it moves. With the smallest moving the fastest it gives an almost 3d effect of a worm like creature moving around the screen.





No comments:

Post a Comment