09779d9a3409a634b698261612af23d794d71355.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. System.register(["__unresolved_0", "cc", "__unresolved_1"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Component, SpriteFrame, Sprite, Game, _dec, _dec2, _class, _class2, _descriptor, _crd, ccclass, property, FrameAnimation;
  4. function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
  5. function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
  6. function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
  7. function _reportPossibleCrUseOfGame(extras) {
  8. _reporterNs.report("Game", "../game/Game", _context.meta, extras);
  9. }
  10. return {
  11. setters: [function (_unresolved_) {
  12. _reporterNs = _unresolved_;
  13. }, function (_cc) {
  14. _cclegacy = _cc.cclegacy;
  15. __checkObsolete__ = _cc.__checkObsolete__;
  16. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  17. _decorator = _cc._decorator;
  18. Component = _cc.Component;
  19. SpriteFrame = _cc.SpriteFrame;
  20. Sprite = _cc.Sprite;
  21. }, function (_unresolved_2) {
  22. Game = _unresolved_2.Game;
  23. }],
  24. execute: function () {
  25. _crd = true;
  26. _cclegacy._RF.push({}, "dba31tmjWBBjISTFQZgGviW", "FrameAnimation", undefined);
  27. __checkObsolete__(['_decorator', 'Component', 'SpriteFrame', 'Sprite']);
  28. ({
  29. ccclass,
  30. property
  31. } = _decorator);
  32. _export("FrameAnimation", FrameAnimation = (_dec = ccclass('FrameAnimation'), _dec2 = property({
  33. type: [SpriteFrame],
  34. tooltip: "播放的帧动画类"
  35. }), _dec(_class = (_class2 = class FrameAnimation extends Component {
  36. constructor() {
  37. super(...arguments);
  38. _initializerDefineProperty(this, "playSFArray", _descriptor, this);
  39. //每一帧的时长
  40. this.duration = 0.1;
  41. //播放完后的回调函数
  42. this.endFunc = null;
  43. //播放到第几帧回调函数
  44. this.playIdxFunc = null;
  45. //播放到第几帧回调函数
  46. this.idx = 0;
  47. //是否播放帧动画
  48. this.isPlayAnim = false;
  49. //记录已经播放的时间
  50. this.playTime = 0;
  51. //是否循环播放
  52. this.loop = true;
  53. //播放的精灵 播放的帧动画
  54. this.currnSprite = null;
  55. //播放帧图片数据
  56. this.playSFs = [];
  57. }
  58. /**
  59. * 播放帧动画
  60. * @param noSp
  61. * @param clipSFs
  62. * @param isLoop
  63. * @param callback
  64. */
  65. play(s, loop, endf, playFun, idx) {
  66. if (s === void 0) {
  67. s = this.duration;
  68. }
  69. if (loop === void 0) {
  70. loop = true;
  71. }
  72. if (endf === void 0) {
  73. endf = () => {};
  74. }
  75. if (playFun === void 0) {
  76. playFun = () => {};
  77. }
  78. if (idx === void 0) {
  79. idx = 0;
  80. }
  81. if (!loop) {
  82. if (this.isPlayAnim) {
  83. return;
  84. }
  85. }
  86. if (this.playSFArray.length > 0) {
  87. this.playSFs = this.playSFArray;
  88. }
  89. if (!this.currnSprite) {
  90. this.currnSprite = this.node.getComponent(Sprite);
  91. }
  92. if (this.playSFs.length > 0) {
  93. this.isPlayAnim = true;
  94. this.playTime = 0;
  95. this.loop = loop;
  96. this.duration = s / this.playSFs.length;
  97. this.endFunc = endf;
  98. this.idx = idx;
  99. this.currnSprite.spriteFrame = this.playSFs[0];
  100. this.playIdxFunc = playFun;
  101. } else {
  102. this.isPlayAnim = false;
  103. }
  104. }
  105. update(deltaTime) {
  106. if (!this.isPlayAnim || !this.currnSprite || !this.currnSprite.node.active) {
  107. return;
  108. }
  109. var g = (_crd && Game === void 0 ? (_reportPossibleCrUseOfGame({
  110. error: Error()
  111. }), Game) : Game).I;
  112. if (g && g.isPause) {
  113. return;
  114. } //累计时间,通过时间计算应该取哪一张图片展示
  115. this.playTime += deltaTime;
  116. var index = Math.floor(this.playTime / this.duration);
  117. if (this.loop) {
  118. // 循环播放
  119. if (index >= this.playSFs.length) {
  120. index -= this.playSFs.length;
  121. this.playTime -= this.duration * this.playSFs.length;
  122. }
  123. this.currnSprite.spriteFrame = this.playSFs[index];
  124. } else {
  125. //播放一次
  126. if (index >= this.playSFs.length) {
  127. var _this$endFunc;
  128. this.isPlayAnim = false; //如果有回调函数的处理,则调用回调函数
  129. (_this$endFunc = this.endFunc) == null || _this$endFunc.call(this);
  130. } else {
  131. this.currnSprite.spriteFrame = this.playSFs[index];
  132. }
  133. if (this.playIdxFunc && this.idx == index) {
  134. this.playIdxFunc();
  135. }
  136. }
  137. }
  138. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "playSFArray", [_dec2], {
  139. configurable: true,
  140. enumerable: true,
  141. writable: true,
  142. initializer: function initializer() {
  143. return [];
  144. }
  145. })), _class2)) || _class));
  146. _cclegacy._RF.pop();
  147. _crd = false;
  148. }
  149. };
  150. });
  151. //# sourceMappingURL=09779d9a3409a634b698261612af23d794d71355.js.map