数学、物理算法ActionScript实现(2)

1.简单的缓动

A:

sprite.vx=(targetX-sprite.x)*easing;

sprite.vy=(targetY-sprite.y)*easing;

sprite.x+=sprite.vx;

sprite.y+=sprite.vy;

B:

var dx:Number=targetX-sprite.x;

var dy:Number=targetY-sprite.y;

sprite.vx=dx*easing;

sprite.vy=dy*easing;

sprite.x+=sprite.vx;

sprite.y+=sprite.vy;

C:

sprite.x+=(targetX-sprite.x)*easing;

sprite.y+=(targetY-sprite.y)*easing;

2.简单的弹性

A:

var ax:Number=(targetX-sprite.x)*spring;

var ay:Number=(targetY-sprite.y)*spring;

sprite.vx+=ax;

sprite.vy+=ay;

sprite.vx*=friction;

sprite.vy*=friction;

sprite.x+=sprite.vx;

sprite.y+=sprite.vy;

B:

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

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

sprite.vx*=friction;

sprite.vy*=friction;

sprite.x+=sprite.vx;

sprite.y+=sprite.vy;

C:

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

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

sprite.x+=(vx*=friction);

sprite.y+=(vy*=friction);

3.弹性偏移

var dx:Number=sprite.x-fixedX;

var dy:Number=sprite.y-fixedY;

var angle:Number=Math.atan2(dy,dx);

var targetX:Number=fixedX+Math.cos(angle)*springLength;

var targetY:Number=fixedY+Math.sin(angle)*springLength;

 

数学、物理算法ActionScript实现(1)

posted @ 2009-01-03 21:57  HelloCG  阅读(304)  评论(0编辑  收藏  举报