对于缓冲公式的抽象
对于缓冲公式的原理这里就不再赘述了,翻翻论坛都能找到。
本来是想做成一个类来调用,结构发现整个代码才10行左右
干脆就做成一个函数调用算了……
设数轴上a、b两点间距离为x,我们有:
x=b-a,(a<b)
x=a-b,(a>b)
然后将方向判断封装在函数中:
x=-(a-b),(a>b)
即:
x=b-a,(a>b)
最终函数为:
function go(a:Number, b:Number):Number {
this.$a = a;
this.$b = b;
if (this.$a>this.$b) {
return this.$a-this.$b;
} else if (this.$a<this.$b) {
return this.$a-this.$b;
} else {
return 0;
}
}
ok,下面我们假设有一个my_mc,要使其缓冲移动到(200,300)这个坐标,代码如下:
本来是想做成一个类来调用,结构发现整个代码才10行左右
干脆就做成一个函数调用算了……
设数轴上a、b两点间距离为x,我们有:
x=b-a,(a<b)
x=a-b,(a>b)
然后将方向判断封装在函数中:
x=-(a-b),(a>b)
即:
x=b-a,(a>b)
最终函数为:
function go(a:Number, b:Number):Number {
this.$a = a;
this.$b = b;
if (this.$a>this.$b) {
return this.$a-this.$b;
} else if (this.$a<this.$b) {
return this.$a-this.$b;
} else {
return 0;
}
}
ok,下面我们假设有一个my_mc,要使其缓冲移动到(200,300)这个坐标,代码如下:
//函数定义
function go(a:Number, b:Number):Number {
this.$a = a;
this.$b = b;
if (this.$a>this.$b) {
return this.$a-this.$b;
} else if (this.$a<this.$b) {
return this.$a-this.$b;
} else {
return 0;
}
}
//缓动系数
var i = 2;
onMouseDown = function () {
this.onEnterFrame = function() {
my_mc._x += go(200, my_mc._x)/i;
my_mc._y += go(300, my_mc._y)/i;
if (Math.floor(go(200, my_mc._x)) == 0) {
delete this.onEnterFrame;
}
};
};[2005-5-19 23:0]

