a499aa9bff2a1818e065dc11bd8ab5f3e352ae6e.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. System.register(["cc"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, CCBoolean, CCFloat, CCInteger, Component, Rect, Size, Sprite, SpriteFrame, Texture2D, UITransform, Vec2, _decorator, _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _dec12, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _descriptor9, _descriptor10, _descriptor11, _crd, ccclass, property, MovieClip;
  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. return {
  8. setters: [function (_cc) {
  9. _cclegacy = _cc.cclegacy;
  10. __checkObsolete__ = _cc.__checkObsolete__;
  11. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  12. CCBoolean = _cc.CCBoolean;
  13. CCFloat = _cc.CCFloat;
  14. CCInteger = _cc.CCInteger;
  15. Component = _cc.Component;
  16. Rect = _cc.Rect;
  17. Size = _cc.Size;
  18. Sprite = _cc.Sprite;
  19. SpriteFrame = _cc.SpriteFrame;
  20. Texture2D = _cc.Texture2D;
  21. UITransform = _cc.UITransform;
  22. Vec2 = _cc.Vec2;
  23. _decorator = _cc._decorator;
  24. }],
  25. execute: function () {
  26. _crd = true;
  27. _cclegacy._RF.push({}, "008df+Vqs9NT7+AfYBNY6bw", "MovieClip", undefined);
  28. __checkObsolete__(['CCBoolean', 'CCFloat', 'CCInteger', 'Component', 'Rect', 'Size', 'Sprite', 'SpriteFrame', 'Texture2D', 'UITransform', 'Vec2', '_decorator']);
  29. ({
  30. ccclass,
  31. property
  32. } = _decorator);
  33. /**
  34. * 动画播放器
  35. * @author
  36. *
  37. */
  38. _export("default", MovieClip = (_dec = ccclass('MovieClip'), _dec2 = property({
  39. type: CCFloat
  40. }), _dec3 = property({
  41. type: Texture2D
  42. }), _dec4 = property({
  43. type: CCInteger
  44. }), _dec5 = property({
  45. type: CCInteger
  46. }), _dec6 = property({
  47. type: CCInteger
  48. }), _dec7 = property({
  49. type: CCInteger
  50. }), _dec8 = property(CCBoolean), _dec9 = property(CCBoolean), _dec10 = property(CCBoolean), _dec11 = property(CCFloat), _dec12 = property(CCFloat), _dec(_class = (_class2 = class MovieClip extends Component {
  51. constructor(...args) {
  52. super(...args);
  53. /** Sprite渲染器 */
  54. this.m_sprite = null;
  55. /** 动画计时间隔 每隔0.1s更新一帧 */
  56. this.timer = 0.1;
  57. /** 播放 时间 间隔 */
  58. _initializerDefineProperty(this, "interval", _descriptor, this);
  59. /** 贴图文件名 */
  60. _initializerDefineProperty(this, "texture", _descriptor2, this);
  61. /** 播放次数 */
  62. _initializerDefineProperty(this, "playTimes", _descriptor3, this);
  63. _initializerDefineProperty(this, "row", _descriptor4, this);
  64. /** 图片切割成几列 */
  65. _initializerDefineProperty(this, "col", _descriptor5, this);
  66. _initializerDefineProperty(this, "rowIndex", _descriptor6, this);
  67. _initializerDefineProperty(this, "isAll", _descriptor7, this);
  68. _initializerDefineProperty(this, "autoPlayOnLoad", _descriptor8, this);
  69. /** 播放完自动销毁 */
  70. _initializerDefineProperty(this, "autoDestroy", _descriptor9, this);
  71. _initializerDefineProperty(this, "begin", _descriptor10, this);
  72. _initializerDefineProperty(this, "end", _descriptor11, this);
  73. /** 动画帧数 */
  74. this.totalFrame = 8;
  75. /** 当前帧数 */
  76. this.currentFrame = 0;
  77. /** 当前播放了第几次 */
  78. this.currentTimes = 0;
  79. /** 影片是否在跑动中 */
  80. this.running = true;
  81. //private _direction:number = 1;
  82. this._playIndex = 0;
  83. this._pieceWidth = 0;
  84. this._pieceHeight = 0;
  85. this._bitmapArr = [];
  86. }
  87. onLoad() {
  88. //this. m_clips = new SpriteFrame[this.row][this.col];
  89. //Texture2D tex = Resources.Load<Texture2D>("Image/Avatar/" + m_sprite_name);
  90. //this.begin = 0;
  91. if (this.end == 0) {
  92. this.end = this.col;
  93. }
  94. this.rowIndex = this.clamp(this.rowIndex, 0, this.row - 1);
  95. this._pieceWidth = this.texture.width / this.col;
  96. this._pieceHeight = this.texture.height / this.row;
  97. this.m_sprite = this.getComponent(Sprite);
  98. if (!this.m_sprite) {
  99. this.m_sprite = this.addComponent(Sprite);
  100. }
  101. for (var i = 0; i < this.row; i++) {
  102. this._bitmapArr[i] = [];
  103. for (var j = 0; j < this.col; j++) {
  104. var spriteFrame = new SpriteFrame();
  105. spriteFrame.texture = this.texture;
  106. spriteFrame.rect = new Rect(j * this._pieceWidth, i * this._pieceHeight, this._pieceWidth, this._pieceHeight);
  107. spriteFrame.rotated = false;
  108. spriteFrame.offset = new Vec2(0, 0);
  109. spriteFrame.originalSize = new Size(this._pieceWidth, this._pieceHeight);
  110. this._bitmapArr[i][j] = spriteFrame;
  111. }
  112. }
  113. this.m_sprite.spriteFrame = this._bitmapArr[this.rowIndex][0];
  114. this.m_sprite.spriteFrame.width;
  115. var uiTransform = this.getComponent(UITransform);
  116. if (uiTransform) {
  117. uiTransform.width = this._pieceWidth;
  118. uiTransform.height = this._pieceHeight;
  119. }
  120. this.timer = 0;
  121. this.running = this.autoPlayOnLoad;
  122. }
  123. update(dt) {
  124. if (!this.running) return;
  125. if (this.playTimes != 0 && this.currentTimes == this.playTimes) {
  126. this.running = false;
  127. return;
  128. }
  129. this.timer -= dt;
  130. if (this.timer <= 0) {
  131. this.timer = this.interval;
  132. this.currentFrame = this.currentFrame % this.col;
  133. this.playAction();
  134. this.currentFrame++;
  135. if (this.currentFrame == this.col) {
  136. if (this.isAll) {
  137. this.rowIndex++;
  138. if (this.rowIndex == this.row) {
  139. this.currentTimes++;
  140. this.node.emit("completeTimes");
  141. if (this.playTimes != 0 && this.currentTimes == this.playTimes) {
  142. this.node.emit("complete");
  143. if (this.autoDestroy) {
  144. this.node.destroy();
  145. }
  146. }
  147. }
  148. this.rowIndex %= this.row;
  149. } else {
  150. this.currentTimes++;
  151. this.node.emit("completeTimes");
  152. if (this.playTimes != 0 && this.currentTimes == this.playTimes) {
  153. this.node.emit("complete");
  154. if (this.autoDestroy) {
  155. this.node.destroy();
  156. }
  157. }
  158. }
  159. }
  160. }
  161. }
  162. playAction() {
  163. this.rowIndex = this.clamp(this.rowIndex, 0, this.row - 1);
  164. this._playIndex = this._playIndex % (this.end - this.begin) + this.begin;
  165. this.m_sprite.spriteFrame = this._bitmapArr[this.rowIndex][this._playIndex]; //this.m_sprite.spriteFrame.setRect(this.rect);
  166. this._playIndex++;
  167. }
  168. /** 播放影片 */
  169. play() {
  170. this.running = true;
  171. }
  172. /** 停止播放影片 */
  173. stop() {
  174. this.running = false;
  175. }
  176. /**
  177. * 跳帧播放
  178. * @param frame 帧
  179. */
  180. gotoAndPlay(frame) {
  181. this.running = true;
  182. this._playIndex = frame;
  183. this._playIndex = this.clamp(this._playIndex, 0, this.col - 1);
  184. }
  185. /**
  186. * 跳帧停止
  187. * @param frame 帧
  188. */
  189. gotoAndStop(frame) {
  190. this.running = false;
  191. this._playIndex = frame;
  192. this._playIndex = this.clamp(this._playIndex, 0, this.col - 1);
  193. this.m_sprite.spriteFrame = this._bitmapArr[this.rowIndex][this._playIndex];
  194. }
  195. clamp(value, minLimit, maxLimit) {
  196. if (value < minLimit) {
  197. return minLimit;
  198. }
  199. if (value > maxLimit) {
  200. return maxLimit;
  201. }
  202. return value;
  203. }
  204. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "interval", [_dec2], {
  205. configurable: true,
  206. enumerable: true,
  207. writable: true,
  208. initializer: function () {
  209. return 0.1;
  210. }
  211. }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "texture", [_dec3], {
  212. configurable: true,
  213. enumerable: true,
  214. writable: true,
  215. initializer: function () {
  216. return null;
  217. }
  218. }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "playTimes", [_dec4], {
  219. configurable: true,
  220. enumerable: true,
  221. writable: true,
  222. initializer: function () {
  223. return 0;
  224. }
  225. }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "row", [_dec5], {
  226. configurable: true,
  227. enumerable: true,
  228. writable: true,
  229. initializer: function () {
  230. return 4;
  231. }
  232. }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "col", [_dec6], {
  233. configurable: true,
  234. enumerable: true,
  235. writable: true,
  236. initializer: function () {
  237. return 4;
  238. }
  239. }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "rowIndex", [_dec7], {
  240. configurable: true,
  241. enumerable: true,
  242. writable: true,
  243. initializer: function () {
  244. return 0;
  245. }
  246. }), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "isAll", [_dec8], {
  247. configurable: true,
  248. enumerable: true,
  249. writable: true,
  250. initializer: function () {
  251. return false;
  252. }
  253. }), _descriptor8 = _applyDecoratedDescriptor(_class2.prototype, "autoPlayOnLoad", [_dec9], {
  254. configurable: true,
  255. enumerable: true,
  256. writable: true,
  257. initializer: function () {
  258. return true;
  259. }
  260. }), _descriptor9 = _applyDecoratedDescriptor(_class2.prototype, "autoDestroy", [_dec10], {
  261. configurable: true,
  262. enumerable: true,
  263. writable: true,
  264. initializer: function () {
  265. return false;
  266. }
  267. }), _descriptor10 = _applyDecoratedDescriptor(_class2.prototype, "begin", [_dec11], {
  268. configurable: true,
  269. enumerable: true,
  270. writable: true,
  271. initializer: function () {
  272. return 0;
  273. }
  274. }), _descriptor11 = _applyDecoratedDescriptor(_class2.prototype, "end", [_dec12], {
  275. configurable: true,
  276. enumerable: true,
  277. writable: true,
  278. initializer: function () {
  279. return 0;
  280. }
  281. })), _class2)) || _class));
  282. _cclegacy._RF.pop();
  283. _crd = false;
  284. }
  285. };
  286. });
  287. //# sourceMappingURL=a499aa9bff2a1818e065dc11bd8ab5f3e352ae6e.js.map