particle.as

来自「小鱼历险记游戏」· AS 代码 · 共 44 行

AS
44 行
字号
import mx.events.EventDispatcher;
class game.phys.Particle {
	public var addEventListener:Function;
	public var removeEventListener:Function;
	private var dispatchEvent:Function;
	public var _target:MovieClip;
	//方向
	public var _dirx:Number;
	public var _diry:Number;
	//到终点的运动次数
	public var _time:Number;
	//终点
	public var _endx:Number;
	public var _endy:Number;
	public function Particle() {
		EventDispatcher.initialize(this);
	}
	//运动方法
	public function play():Void {
		var tx = _target._x;
		var ty = _target._y;
		_dirx = (_endx>=tx) ? 1 : -1;
		_diry = (_endy>=ty) ? 1 : -1;
		var dx = Math.abs((_endx-tx)/_time);
		var dy = Math.abs((_endy-ty)/_time);
		var t = 0;
		var ins = this;
		_target.onEnterFrame = function() {
			var dx = Math.abs((ins._endx-tx)/ins._time);
			var dy = Math.abs((ins._endy-ty)/ins._time);
			tx += dx*ins._dirx;
			ty += dy*ins._diry;
			this._x = tx;
			this._y = ty;
			t++;
			ins.dispatchEvent({type:"onPlay", target:this});
			if (t>=ins._time) {
				delete this.onEnterFrame;
				ins.dispatchEvent({type:"onStop", target:this});
			}
		};
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?