MovieClip.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var s =
  5. (this && this.__decorate) ||
  6. function (t, e, i, s) {
  7. var o,
  8. a = arguments.length,
  9. n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
  10. if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
  11. else
  12. for (var r = t.length - 1; 0 <= r; r--)
  13. (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
  14. return 3 < a && n && Object.defineProperty(e, i, n), n;
  15. };
  16. Object.defineProperty(i, "__esModule", {value: !0});
  17. const {ccclass: o, property: a} = cc._decorator;
  18. e = class extends cc.Component {
  19. constructor() {
  20. super(...arguments),
  21. (this.m_sprite = null),
  22. (this.timer = 0.1),
  23. (this.interval = 0.1),
  24. (this.texture = null),
  25. (this.playTimes = 0),
  26. (this.row = 4),
  27. (this.col = 4),
  28. (this.rowIndex = 0),
  29. (this.isAll = !1),
  30. (this.autoPlayOnLoad = !0),
  31. (this.autoDestroy = !1),
  32. (this.begin = 0),
  33. (this.end = 0),
  34. (this.totalFrame = 8),
  35. (this.currentFrame = 0),
  36. (this.currentTimes = 0),
  37. (this.running = !0),
  38. (this._playIndex = 0),
  39. (this._pieceWidth = 0),
  40. (this._pieceHeight = 0),
  41. (this._bitmapArr = []);
  42. }
  43. onLoad() {
  44. 0 == this.end && (this.end = this.col),
  45. (this.rowIndex = this.clamp(this.rowIndex, 0, this.row - 1)),
  46. (this._pieceWidth = this.texture.width / this.col),
  47. (this._pieceHeight = this.texture.height / this.row),
  48. (this.m_sprite = this.getComponent(cc.Sprite)),
  49. this.m_sprite || (this.m_sprite = this.addComponent(cc.Sprite));
  50. for (var t = 0; t < this.row; t++) {
  51. this._bitmapArr[t] = [];
  52. for (var e = 0; e < this.col; e++)
  53. this._bitmapArr[t][e] = new cc.SpriteFrame(
  54. this.texture,
  55. new cc.Rect(e * this._pieceWidth, t * this._pieceHeight, this._pieceWidth, this._pieceHeight),
  56. !1,
  57. cc.v2(0, 0),
  58. new cc.Size(this._pieceWidth, this._pieceHeight)
  59. );
  60. }
  61. (this.m_sprite.spriteFrame = this._bitmapArr[this.rowIndex][0]),
  62. (this.node.width = this._pieceWidth),
  63. (this.node.height = this._pieceHeight),
  64. (this.timer = 0),
  65. (this.running = this.autoPlayOnLoad);
  66. }
  67. update(t) {
  68. this.running &&
  69. (0 == this.playTimes || this.currentTimes != this.playTimes
  70. ? ((this.timer -= t),
  71. this.timer <= 0 &&
  72. ((this.timer = this.interval),
  73. (this.currentFrame = this.currentFrame % this.col),
  74. this.playAction(),
  75. this.currentFrame++,
  76. this.currentFrame == this.col &&
  77. (this.isAll
  78. ? (this.rowIndex++,
  79. this.rowIndex == this.row &&
  80. (this.currentTimes++,
  81. this.node.emit("completeTimes"),
  82. 0 != this.playTimes &&
  83. this.currentTimes == this.playTimes &&
  84. (this.node.emit("complete"), this.autoDestroy && this.node.destroy())),
  85. (this.rowIndex %= this.row))
  86. : (this.currentTimes++,
  87. this.node.emit("completeTimes"),
  88. 0 != this.playTimes &&
  89. this.currentTimes == this.playTimes &&
  90. (this.node.emit("complete"), this.autoDestroy && this.node.destroy())))))
  91. : (this.running = !1));
  92. }
  93. playAction() {
  94. (this.rowIndex = this.clamp(this.rowIndex, 0, this.row - 1)),
  95. (this._playIndex = (this._playIndex % (this.end - this.begin)) + this.begin),
  96. (this.m_sprite.spriteFrame = this._bitmapArr[this.rowIndex][this._playIndex]),
  97. this._playIndex++;
  98. }
  99. play() {
  100. this.running = !0;
  101. }
  102. stop() {
  103. this.running = !1;
  104. }
  105. gotoAndPlay(t) {
  106. (this.running = !0), (this._playIndex = t), (this._playIndex = this.clamp(this._playIndex, 0, this.col - 1));
  107. }
  108. gotoAndStop(t) {
  109. (this.running = !1),
  110. (this._playIndex = t),
  111. (this._playIndex = this.clamp(this._playIndex, 0, this.col - 1)),
  112. (this.m_sprite.spriteFrame = this._bitmapArr[this.rowIndex][this._playIndex]);
  113. }
  114. clamp(t, e, i) {
  115. return t < e ? e : i < t ? i : t;
  116. }
  117. };
  118. s([a(cc.Float)], e.prototype, "interval", void 0),
  119. s([a({type: cc.Texture2D})], e.prototype, "texture", void 0),
  120. s([a({type: cc.Integer})], e.prototype, "playTimes", void 0),
  121. s([a(cc.Integer)], e.prototype, "row", void 0),
  122. s([a(cc.Integer)], e.prototype, "col", void 0),
  123. s([a(cc.Integer)], e.prototype, "rowIndex", void 0),
  124. s([a(cc.Boolean)], e.prototype, "isAll", void 0),
  125. s([a(cc.Boolean)], e.prototype, "autoPlayOnLoad", void 0),
  126. s([a(cc.Boolean)], e.prototype, "autoDestroy", void 0),
  127. s([a()], e.prototype, "begin", void 0),
  128. s([a()], e.prototype, "end", void 0),
  129. (e = s([o], e)),
  130. (i.default = e);