e512dc23403afb33626ea89a8cd4f5314eea8fae.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. System.register(["cc"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Vec3, Shake, _crd;
  4. function get_new_shake(startPos = new Vec3(0, 0, 0)) {
  5. return new Shake(startPos);
  6. }
  7. _export("default", get_new_shake);
  8. return {
  9. setters: [function (_cc) {
  10. _cclegacy = _cc.cclegacy;
  11. __checkObsolete__ = _cc.__checkObsolete__;
  12. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  13. Vec3 = _cc.Vec3;
  14. }],
  15. execute: function () {
  16. _crd = true;
  17. _cclegacy._RF.push({}, "88adahxArtIPKhtXnEB29+o", "Shake", undefined);
  18. __checkObsolete__(['Vec3']);
  19. Shake = class Shake {
  20. constructor(startPos = new Vec3(0, 0, 0)) {
  21. this.intensity = void 0;
  22. this.duration = void 0;
  23. this.shakePos = new Vec3(0, 0, 0);
  24. this.startPos = startPos;
  25. this.duration = 0;
  26. this.intensity = 0;
  27. }
  28. /**改变初起点*/
  29. setStartPos(x, y) {
  30. this.startPos.x = x;
  31. this.startPos.y = y;
  32. }
  33. /**开始抖动
  34. * duration 时间
  35. * intensity 强度
  36. */
  37. start(duration = 0.3, intensity = 3.8) {
  38. this.duration = duration;
  39. this.intensity = intensity;
  40. }
  41. /**停止抖动*/
  42. stop() {
  43. this.shakePos.x = this.startPos.x;
  44. this.shakePos.y = this.startPos.y;
  45. this.duration = 0;
  46. return this.shakePos;
  47. }
  48. getShakePos() {
  49. return this.shakePos;
  50. }
  51. action(dt) {
  52. if (this.duration > 0) {
  53. this.duration -= dt;
  54. if (this.duration <= 0) {
  55. return this.stop();
  56. } else {
  57. const randomX = Math.random() * this.intensity - this.intensity * 0.5;
  58. const randomY = Math.random() * this.intensity - this.intensity * 0.5;
  59. this.shakePos.x = this.startPos.x + randomX;
  60. this.shakePos.y = this.startPos.y + randomY;
  61. return this.shakePos;
  62. }
  63. }
  64. return null;
  65. }
  66. };
  67. _cclegacy._RF.pop();
  68. _crd = false;
  69. }
  70. };
  71. });
  72. //# sourceMappingURL=e512dc23403afb33626ea89a8cd4f5314eea8fae.js.map