SwitchFrame.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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, menu: n, requireComponent: r, executeInEditMode: l } = cc._decorator;
  18. e = class extends cc.Component {
  19. constructor() {
  20. super(...arguments), (this.fames = []), (this._frameIndex = 0), (this.sprite = null);
  21. }
  22. set frameIndex(t) {
  23. null == t ? (this._frameIndex = t) : t !== this._frameIndex && this.switch(t);
  24. }
  25. get frameIndex() {
  26. return this._frameIndex;
  27. }
  28. get framNum() {
  29. return this.fames.length;
  30. }
  31. onLoad() {
  32. this.sprite || (this.sprite = this.getComponent(cc.Sprite));
  33. }
  34. start() {
  35. this.switch(this._frameIndex);
  36. }
  37. switch (t) {
  38. this.sprite &&
  39. this.sprite.spriteFrame !== this.fames[t] &&
  40. this.fames[t] &&
  41. (this.sprite.spriteFrame = this.fames[t]),
  42. (this._frameIndex = t);
  43. }
  44. };
  45. s([a({ type: cc.SpriteFrame })], e.prototype, "fames", void 0),
  46. s([a()], e.prototype, "frameIndex", null),
  47. s([a(cc.Sprite)], e.prototype, "sprite", void 0),
  48. (e = s([o, r(cc.Sprite), l], e)),
  49. (i.default = e);