123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- 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();
- let 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 = null) {
- if (this._percentSpeed == 0 && this._percentAddSpeed == 0) return this._current;
- this._percentSpeed += this._percentAddSpeed * dt;
- this._percent += this._percentSpeed * dt;
- let 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=cf9c45e29398b29856527964dd8d734c5d4fdec4.js.map
|