基本就是:
mc._x = mc._x + (给定值或_ymouse-mc._x-[mc._width/2])*缓冲系数
其中[mc._width/2]是为了让鼠标对准mc的中心,如果是给定值完全可以不要,缓冲系数就是每次循环靠近给定值或鼠标的系数,而达到缓冲的效果。
如:
on (rollOver)
{
_root.mc.wz = -100;
}
onClipEvent (load)
{
wz = this._x;
}
onClipEvent (enterFrame)
{
this._x = this._x + (wz - this._x) * 0.200000;
//trace(this._x);
}
如:
_root.onEnterFrame = function(){
mc._y = mc._y + (_ymouse - mc._y ) *0.2;
}
当然,缓冲公式不只是用于位置的移动,还适用于_xscale, _rotation等其他属性的应用。
如:
xxx = random(100);
yyy = random(100);
mc1.onEnterFrame = function ()
{
this._xscale = this._xscale + (xxx - this._xscale) * 0.2;
this._yscale = this._yscale + (yyy - this._yscale) * 0.2;
};
rrr = random(360);
mc2.onEnterFrame = function ()
{
this._rotation = this._rotation + (rrr - this._rotation) * 0.1;
}
关于缓冲公式的抽象
本来是想做成一个类来调用,结构发现整个代码才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;
}
};
};
用中文写了一个缓冲公式,应该非常容易理解:
function 缓冲(目标, 对象, 缓冲系数) {
距离x = 目标-对象._x;
距离y = 目标-对象._y;
缓冲x = 距离x*缓冲系数;
缓冲x = 距离x*缓冲系数;
对象._x += 缓冲x;
对象._y += 缓冲y;
}//这里把缓冲的函数封装了一下,下面的实例
onEnterFrame = function () {
缓冲(_xmouse, ball, 0.2);//目标,对象,缓冲系数
};
一个Flash缓冲导航详解
www.blueidea.com/tech/multimedia/2004/1755.asp
mc._x = mc._x + (给定值或_ymouse-mc._x-[mc._width/2])*缓冲系数
其中[mc._width/2]是为了让鼠标对准mc的中心,如果是给定值完全可以不要,缓冲系数就是每次循环靠近给定值或鼠标的系数,而达到缓冲的效果。
如:
on (rollOver)
{
_root.mc.wz = -100;
}
onClipEvent (load)
{
wz = this._x;
}
onClipEvent (enterFrame)
{
this._x = this._x + (wz - this._x) * 0.200000;
//trace(this._x);
}
如:
_root.onEnterFrame = function(){
mc._y = mc._y + (_ymouse - mc._y ) *0.2;
}
当然,缓冲公式不只是用于位置的移动,还适用于_xscale, _rotation等其他属性的应用。
如:
xxx = random(100);
yyy = random(100);
mc1.onEnterFrame = function ()
{
this._xscale = this._xscale + (xxx - this._xscale) * 0.2;
this._yscale = this._yscale + (yyy - this._yscale) * 0.2;
};
rrr = random(360);
mc2.onEnterFrame = function ()
{
this._rotation = this._rotation + (rrr - this._rotation) * 0.1;
}
关于缓冲公式的抽象
本来是想做成一个类来调用,结构发现整个代码才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;
}
};
};
用中文写了一个缓冲公式,应该非常容易理解:
function 缓冲(目标, 对象, 缓冲系数) {
距离x = 目标-对象._x;
距离y = 目标-对象._y;
缓冲x = 距离x*缓冲系数;
缓冲x = 距离x*缓冲系数;
对象._x += 缓冲x;
对象._y += 缓冲y;
}//这里把缓冲的函数封装了一下,下面的实例
onEnterFrame = function () {
缓冲(_xmouse, ball, 0.2);//目标,对象,缓冲系数
};
一个Flash缓冲导航详解
www.blueidea.com/tech/multimedia/2004/1755.asp
回复Comments
{commenttime}{commentauthor}
{CommentUrl}
{commentcontent}