flash跟随鼠标图片缓动效果
Flash 2011/6/30 18:41:02 点击:不统计
<网f站o学a习s制p作.cn>
做了一个跟随鼠标缓动效果,代码如下,并有解释
var a_X:Number;
var a_Y:Number;
var c_X:Number;
var c_Y:Number;
var speed:Number =10;
var len:Number = 300;
this.addEventListener(Event.ENTER_FRAME,ac);
function ac(me:Event):void{
//trace(stage.mouseX);首先获star位置
//Mouse.hide();
c_X = stage.mouseX - star.x;
c_Y = stage.mouseY - star.y;
//a_X = Math.abs(c_X)>len?speed:(Math.abs(c_X)/len)*speed;
//a_Y = Math.abs(c_Y)>len?speed:(Math.abs(c_Y)/len)*speed;
a_X = (Math.abs(c_X)/len)*speed;
a_Y = (Math.abs(c_Y)/len)*speed;
if(c_X<0)a_X = -a_X;
if(c_Y<0)a_Y = -a_Y;
star.x = Math.abs(c_X)<0.1?stage.mouseX:star.x + a_X;
star.y = Math.abs(c_Y)<0.1?stage.mouseY:star.y + a_Y;
}
效果如下:
http://%77%77%77%2E%66网站制作%6F学习网%72%61%73%70%2E%63%6E