123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- var t = require;
- var e = module;
- var i = exports;
- var s =
- (this && this.__decorate) ||
- function (t, e, i, s) {
- var o,
- a = arguments.length,
- n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
- if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
- else
- for (var r = t.length - 1; 0 <= r; r--)
- (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
- return 3 < a && n && Object.defineProperty(e, i, n), n;
- };
- Object.defineProperty(i, "__esModule", {value: !0});
- const {ccclass: o, property: a} = cc._decorator;
- e = class extends cc.Component {
- constructor() {
- super(...arguments),
- (this.m_sprite = null),
- (this.timer = 0.1),
- (this.interval = 0.1),
- (this.texture = null),
- (this.playTimes = 0),
- (this.row = 4),
- (this.col = 4),
- (this.rowIndex = 0),
- (this.isAll = !1),
- (this.autoPlayOnLoad = !0),
- (this.autoDestroy = !1),
- (this.begin = 0),
- (this.end = 0),
- (this.totalFrame = 8),
- (this.currentFrame = 0),
- (this.currentTimes = 0),
- (this.running = !0),
- (this._playIndex = 0),
- (this._pieceWidth = 0),
- (this._pieceHeight = 0),
- (this._bitmapArr = []);
- }
- onLoad() {
- 0 == this.end && (this.end = this.col),
- (this.rowIndex = this.clamp(this.rowIndex, 0, this.row - 1)),
- (this._pieceWidth = this.texture.width / this.col),
- (this._pieceHeight = this.texture.height / this.row),
- (this.m_sprite = this.getComponent(cc.Sprite)),
- this.m_sprite || (this.m_sprite = this.addComponent(cc.Sprite));
- for (var t = 0; t < this.row; t++) {
- this._bitmapArr[t] = [];
- for (var e = 0; e < this.col; e++)
- this._bitmapArr[t][e] = new cc.SpriteFrame(
- this.texture,
- new cc.Rect(e * this._pieceWidth, t * this._pieceHeight, this._pieceWidth, this._pieceHeight),
- !1,
- cc.v2(0, 0),
- new cc.Size(this._pieceWidth, this._pieceHeight)
- );
- }
- (this.m_sprite.spriteFrame = this._bitmapArr[this.rowIndex][0]),
- (this.node.width = this._pieceWidth),
- (this.node.height = this._pieceHeight),
- (this.timer = 0),
- (this.running = this.autoPlayOnLoad);
- }
- update(t) {
- this.running &&
- (0 == this.playTimes || this.currentTimes != this.playTimes
- ? ((this.timer -= t),
- this.timer <= 0 &&
- ((this.timer = this.interval),
- (this.currentFrame = this.currentFrame % this.col),
- this.playAction(),
- this.currentFrame++,
- this.currentFrame == this.col &&
- (this.isAll
- ? (this.rowIndex++,
- this.rowIndex == this.row &&
- (this.currentTimes++,
- this.node.emit("completeTimes"),
- 0 != this.playTimes &&
- this.currentTimes == this.playTimes &&
- (this.node.emit("complete"), this.autoDestroy && this.node.destroy())),
- (this.rowIndex %= this.row))
- : (this.currentTimes++,
- this.node.emit("completeTimes"),
- 0 != this.playTimes &&
- this.currentTimes == this.playTimes &&
- (this.node.emit("complete"), this.autoDestroy && this.node.destroy())))))
- : (this.running = !1));
- }
- playAction() {
- (this.rowIndex = this.clamp(this.rowIndex, 0, this.row - 1)),
- (this._playIndex = (this._playIndex % (this.end - this.begin)) + this.begin),
- (this.m_sprite.spriteFrame = this._bitmapArr[this.rowIndex][this._playIndex]),
- this._playIndex++;
- }
- play() {
- this.running = !0;
- }
- stop() {
- this.running = !1;
- }
- gotoAndPlay(t) {
- (this.running = !0), (this._playIndex = t), (this._playIndex = this.clamp(this._playIndex, 0, this.col - 1));
- }
- gotoAndStop(t) {
- (this.running = !1),
- (this._playIndex = t),
- (this._playIndex = this.clamp(this._playIndex, 0, this.col - 1)),
- (this.m_sprite.spriteFrame = this._bitmapArr[this.rowIndex][this._playIndex]);
- }
- clamp(t, e, i) {
- return t < e ? e : i < t ? i : t;
- }
- };
- s([a(cc.Float)], e.prototype, "interval", void 0),
- s([a({type: cc.Texture2D})], e.prototype, "texture", void 0),
- s([a({type: cc.Integer})], e.prototype, "playTimes", void 0),
- s([a(cc.Integer)], e.prototype, "row", void 0),
- s([a(cc.Integer)], e.prototype, "col", void 0),
- s([a(cc.Integer)], e.prototype, "rowIndex", void 0),
- s([a(cc.Boolean)], e.prototype, "isAll", void 0),
- s([a(cc.Boolean)], e.prototype, "autoPlayOnLoad", void 0),
- s([a(cc.Boolean)], e.prototype, "autoDestroy", void 0),
- s([a()], e.prototype, "begin", void 0),
- s([a()], e.prototype, "end", void 0),
- (e = s([o], e)),
- (i.default = e);
|