缓动

1)何时停止缓动:

private function onEnterFrame(event : Event) : void {

var dx:Number = targetX - ball.x;

if (Math.abs(dx) < 1){

ball.x = targetX;

removeEventListener(Event.ENTER_FRAME,onEnterFrame);

} else {

var vx:Number = dx * easing;

ball.x += vx;

}

}

}

2) 重影效果可以让第一个影子缓动至物体,第二个影子缓动至第一个影子,第三个影子缓动至第二个影子。。。

function onEnterFrame(event:Event): void{

moveBall(ball0,mouseX,mouseY);

moveBall(ball1,ball0.x,ball0.y);

moveBall(ball2,ball1.x,ball1.y);

}

private function moveBall(ball:Ball,targetX:Number,targetY:Number):void{

ball.vx += (targetX - ball.x) * spring;

ball.vy += (targetY - ball.y) * spring;

ball.vy += gravity;

ball.vx *= friction;

ball.vy *= friction;

ball.x += ball.vx;

ball.y += ball.vy;

}

3) 缓动:

ball.x += (targetX - ball.x) * 0.2;

ball.y += (targetY - ball.y) * 0.2;

4) 弹性:

dx = targetX - ball.x;

dy = targetY - ball.y;

ax = dx * 0.2;

ay = dx * 0.2;

vx += ax;

vy += ay;

vx *= friction;

vy *= friction;

ball.x += vx;

ball.y += vy;

原文地址:https://www.cnblogs.com/cly84920/p/4426645.html