读书人

物体加速度追踪鼠标移动

发布时间: 2012-11-23 22:54:33 作者: rapoo

物体加速度跟踪鼠标移动

先看效果:
?
代码如下:
/*自娱自乐原创flash教程
www.MyGameMyLove.com
2008-1-11?smallerbird?mygamemylove@qq.comBR>*/
//在舞台上放一个电影符号:mc
var?mc:MovieClip;
//速度
//初使速度
mc.sdConst?=?5;
//速度的增量
mc.sdXs?=?1.05;
mc.sd?=?mc.sdConst;
//方向
mc.xfx?=?1;
mc.yfx?=?1;
mc.onEnterFrame?=?function()?{
?mc.sd?*=?this.sdXs;
?var?xm:Number?=?_root._xmouse;
?var?ym:Number?=?_root._ymouse;
?//距离
?var?xd:Number?=?xm-this._x;
?var?yd:Number?=?ym-this._y;
?//确定方向
?if?(xd>0)?{
??this.xfx?=?1;
?}?else?{
??this.xfx?=?-1;
?}
?if?(yd>0)?{
??this.yfx?=?1;
?}?else?{
??this.yfx?=?-1;
?}
?//移动
?if?(Math.abs(xd)>this.sd)?{
??this._x?+=?this.xfx*this.sd;
?}?else?{
??this._x?=?xm;
?}
?if?(Math.abs(yd)>this.sd)?{
??this._y?+=?this.yfx*this.sd;
?}?else?{
??this._y?=?ym;
?}
?//复位xy
?if?(this._x?==?xm?&&?this._y?==?ym)?{
??this.sd?=?this.sdConst;
?}};
本文转自:http://www.5uflash.com/flashjiaocheng/Flashaschengxu/2962.html

读书人网 >Web前端

热点推荐