cf9c45e29398b29856527964dd8d734c5d4fdec4.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. System.register(["cc"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Vec2, Line2DMove, _crd;
  4. _export("Line2DMove", void 0);
  5. return {
  6. setters: [function (_cc) {
  7. _cclegacy = _cc.cclegacy;
  8. __checkObsolete__ = _cc.__checkObsolete__;
  9. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  10. Vec2 = _cc.Vec2;
  11. }],
  12. execute: function () {
  13. _crd = true;
  14. _cclegacy._RF.push({}, "24592yMfD9O6qsVldhDD3Pb", "Line2DMove", undefined);
  15. //直线移动
  16. __checkObsolete__(['Vec2']);
  17. _export("Line2DMove", Line2DMove = class Line2DMove {
  18. /**
  19. * @param start_x 起始点
  20. * @param start_y
  21. * @param end_x 终点
  22. * @param end_y
  23. * @param speed 速度
  24. * @param addSpeed 加速度
  25. * 起点终点一致时没有速度将不起作用
  26. */
  27. constructor(start_x, start_y, end_x, end_y, speed, addSpeed) {
  28. this._s = void 0;
  29. //起始点
  30. this._e = void 0;
  31. //终点
  32. this._percentSpeed = void 0;
  33. this._percentAddSpeed = void 0;
  34. this._percent = void 0;
  35. //进度
  36. this._current = void 0;
  37. this._currentDir = void 0;
  38. /**
  39. * 获取进度位置
  40. * @param t 当前时间进度 0-1
  41. * @param a 起点
  42. * @param b 控制点
  43. * @param c 终点
  44. */
  45. this._ab = new Vec2();
  46. this._s = new Vec2(start_x, start_y);
  47. this._e = new Vec2(end_x, end_y);
  48. this._current = new Vec2(start_x, start_y);
  49. this._currentDir = new Vec2(this._e.x - this._s.x, this._e.y - this._s.y).normalize();
  50. let dis = new Vec2(end_x, end_y).subtract2f(start_x, start_y).length();
  51. if (dis <= 0) {
  52. this._percent = 1;
  53. this._percentSpeed = 0;
  54. this._percentAddSpeed = 0;
  55. } else {
  56. this._percent = 0;
  57. this._percentSpeed = speed / dis;
  58. this._percentAddSpeed = addSpeed / dis;
  59. }
  60. }
  61. get target_pos_x() {
  62. return this._e.x;
  63. }
  64. get target_pos_y() {
  65. return this._e.y;
  66. }
  67. get current_dir() {
  68. return this._currentDir;
  69. }
  70. get isEnd() {
  71. return this._percent >= 1;
  72. }
  73. get percent() {
  74. return this._percent;
  75. }
  76. /**
  77. * 向目标运动
  78. * @param dt 帧时间
  79. * @param mb 目标点,没有的话为初始定义的点
  80. * @returns
  81. */
  82. MoveTo(dt, mb = null) {
  83. if (this._percentSpeed == 0 && this._percentAddSpeed == 0) return this._current;
  84. this._percentSpeed += this._percentAddSpeed * dt;
  85. this._percent += this._percentSpeed * dt;
  86. let nextpos = this.getPos(this._percent, this._s, mb == null ? this._e : mb);
  87. this._current.x = nextpos.x;
  88. this._current.y = nextpos.y;
  89. return this._current;
  90. }
  91. getPos(t, a, b) {
  92. Vec2.lerp(this._ab, a, b, t);
  93. return this._ab;
  94. }
  95. });
  96. _cclegacy._RF.pop();
  97. _crd = false;
  98. }
  99. };
  100. });
  101. //# sourceMappingURL=cf9c45e29398b29856527964dd8d734c5d4fdec4.js.map