AS2簡單的mouse互動class

先制作一個名為 movemouse 的class
程式碼如下:

class followmouse
{
var _x, _y;
function followmouse(x_mc, speed, _damp)
{
var tx = 0;
var ty = 0;
x_mc.onEnterFrame = function ()
{
var _vx = (_xmouse - _x) * speed;
var _vy = (_ymouse - _y) * speed;
tx = tx + _vx;
ty = ty + _vy;
x_mc._x = x_mc._x + tx;
x_mc._y = x_mc._y + ty;
tx = tx * _damp;
ty = ty * _damp;
};
}
}

然後在新建立的fla裡,建立一個實體名稱為ball_mc的影片角色,
在時間軸上下如下的語法
var ballmov:followmouse=new followmouse(ball_mc,0.1,0.9);
ball_mc為場景上的影片名稱,0.1的位置為速度,0.9為摩擦力,
可以代入不同的數字來測試效果。

留言

這個網誌中的熱門文章

Flash CS4有夠慢!