运动公式

来源:互联网 发布:asus ac68u 网络打印 编辑:程序博客网 时间:2024/05/17 02:59

运动公式

2007年01月18日 星期四

当然,以下公式在使用过程中都要循环执行。

1。缓冲运动:

ball._x += (targetX-ball._x)*a;

ball._y += (targetY-ball._y)*a;

//运动的目标是(targetX,targetY)。ball是运动的对象。参数a是控制运动的速度的。(0<1)越大速度越快。

2。震荡运动:

speedx = (targetX-ball._x)*a+speedx*b;
speedy = (targetY-ball._y)*a+speedy*b;
ball._x += speedx;
ball._y += speedy;

//参数b(0< b <=1)是震荡的衰减速度,越大震荡衰减得越慢。1时没有衰减
//参数a(0< a <1)是运动速度,越大运动速度越大

更多内容   在其中也谈到了这种运动。不过公式是另一种形式:

//起始点与目标地点的距离
dx = targetx-my_mc._x;
dy = targety-my_mc._y;
//加速度
vx += dx*.3;
vy += dy*.3;
//加入摩擦
vx *= fraction;
vy *= fraction;
my_mc._x += vx;
my_mc._y += vy;

 
原创粉丝点击