首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

物体加速度追踪鼠标移动

2012-11-23 
物体加速度跟踪鼠标移动先看效果: ?代码如下:/*自娱自乐原创flash教程 www.MyGameMyLove.com 2008-1-11?sm

物体加速度跟踪鼠标移动

先看效果:
?
代码如下:
/*自娱自乐原创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

热点排行