System.register(["cc"], function (_export, _context) { "use strict"; var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Vec2, Line2DMove, _crd; _export("Line2DMove", void 0); return { setters: [function (_cc) { _cclegacy = _cc.cclegacy; __checkObsolete__ = _cc.__checkObsolete__; __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__; Vec2 = _cc.Vec2; }], execute: function () { _crd = true; _cclegacy._RF.push({}, "24592yMfD9O6qsVldhDD3Pb", "Line2DMove", undefined); //直线移动 __checkObsolete__(['Vec2']); _export("Line2DMove", Line2DMove = class Line2DMove { /** * @param start_x 起始点 * @param start_y * @param end_x 终点 * @param end_y * @param speed 速度 * @param addSpeed 加速度 * 起点终点一致时没有速度将不起作用 */ constructor(start_x, start_y, end_x, end_y, speed, addSpeed) { this._s = void 0; //起始点 this._e = void 0; //终点 this._percentSpeed = void 0; this._percentAddSpeed = void 0; this._percent = void 0; //进度 this._current = void 0; this._currentDir = void 0; /** * 获取进度位置 * @param t 当前时间进度 0-1 * @param a 起点 * @param b 控制点 * @param c 终点 */ this._ab = new Vec2(); this._s = new Vec2(start_x, start_y); this._e = new Vec2(end_x, end_y); this._current = new Vec2(start_x, start_y); this._currentDir = new Vec2(this._e.x - this._s.x, this._e.y - this._s.y).normalize(); var dis = new Vec2(end_x, end_y).subtract2f(start_x, start_y).length(); if (dis <= 0) { this._percent = 1; this._percentSpeed = 0; this._percentAddSpeed = 0; } else { this._percent = 0; this._percentSpeed = speed / dis; this._percentAddSpeed = addSpeed / dis; } } get target_pos_x() { return this._e.x; } get target_pos_y() { return this._e.y; } get current_dir() { return this._currentDir; } get isEnd() { return this._percent >= 1; } get percent() { return this._percent; } /** * 向目标运动 * @param dt 帧时间 * @param mb 目标点,没有的话为初始定义的点 * @returns */ MoveTo(dt, mb) { if (mb === void 0) { mb = null; } if (this._percentSpeed == 0 && this._percentAddSpeed == 0) return this._current; this._percentSpeed += this._percentAddSpeed * dt; this._percent += this._percentSpeed * dt; var nextpos = this.getPos(this._percent, this._s, mb == null ? this._e : mb); this._current.x = nextpos.x; this._current.y = nextpos.y; return this._current; } getPos(t, a, b) { Vec2.lerp(this._ab, a, b, t); return this._ab; } }); _cclegacy._RF.pop(); _crd = false; } }; }); //# sourceMappingURL=8a70b8dc94d378ff20528ac810c7a0e513a94128.js.map