System.register(["cc"], function (_export, _context) { "use strict"; 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; 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 }); } 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; } 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.'); } return { setters: [function (_cc) { _cclegacy = _cc.cclegacy; __checkObsolete__ = _cc.__checkObsolete__; __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__; CCBoolean = _cc.CCBoolean; CCFloat = _cc.CCFloat; CCInteger = _cc.CCInteger; Component = _cc.Component; Rect = _cc.Rect; Size = _cc.Size; Sprite = _cc.Sprite; SpriteFrame = _cc.SpriteFrame; Texture2D = _cc.Texture2D; UITransform = _cc.UITransform; Vec2 = _cc.Vec2; _decorator = _cc._decorator; }], execute: function () { _crd = true; _cclegacy._RF.push({}, "008df+Vqs9NT7+AfYBNY6bw", "MovieClip", undefined); __checkObsolete__(['CCBoolean', 'CCFloat', 'CCInteger', 'Component', 'Rect', 'Size', 'Sprite', 'SpriteFrame', 'Texture2D', 'UITransform', 'Vec2', '_decorator']); ({ ccclass, property } = _decorator); /** * 动画播放器 * @author * */ _export("default", MovieClip = (_dec = ccclass('MovieClip'), _dec2 = property({ type: CCFloat }), _dec3 = property({ type: Texture2D }), _dec4 = property({ type: CCInteger }), _dec5 = property({ type: CCInteger }), _dec6 = property({ type: CCInteger }), _dec7 = property({ type: CCInteger }), _dec8 = property(CCBoolean), _dec9 = property(CCBoolean), _dec10 = property(CCBoolean), _dec11 = property(CCFloat), _dec12 = property(CCFloat), _dec(_class = (_class2 = class MovieClip extends Component { constructor() { super(...arguments); /** Sprite渲染器 */ this.m_sprite = null; /** 动画计时间隔 每隔0.1s更新一帧 */ this.timer = 0.1; /** 播放 时间 间隔 */ _initializerDefineProperty(this, "interval", _descriptor, this); /** 贴图文件名 */ _initializerDefineProperty(this, "texture", _descriptor2, this); /** 播放次数 */ _initializerDefineProperty(this, "playTimes", _descriptor3, this); _initializerDefineProperty(this, "row", _descriptor4, this); /** 图片切割成几列 */ _initializerDefineProperty(this, "col", _descriptor5, this); _initializerDefineProperty(this, "rowIndex", _descriptor6, this); _initializerDefineProperty(this, "isAll", _descriptor7, this); _initializerDefineProperty(this, "autoPlayOnLoad", _descriptor8, this); /** 播放完自动销毁 */ _initializerDefineProperty(this, "autoDestroy", _descriptor9, this); _initializerDefineProperty(this, "begin", _descriptor10, this); _initializerDefineProperty(this, "end", _descriptor11, this); /** 动画帧数 */ this.totalFrame = 8; /** 当前帧数 */ this.currentFrame = 0; /** 当前播放了第几次 */ this.currentTimes = 0; /** 影片是否在跑动中 */ this.running = true; //private _direction:number = 1; this._playIndex = 0; this._pieceWidth = 0; this._pieceHeight = 0; this._bitmapArr = []; } onLoad() { //this. m_clips = new SpriteFrame[this.row][this.col]; //Texture2D tex = Resources.Load("Image/Avatar/" + m_sprite_name); //this.begin = 0; if (this.end == 0) { 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(Sprite); if (!this.m_sprite) { this.m_sprite = this.addComponent(Sprite); } for (var i = 0; i < this.row; i++) { this._bitmapArr[i] = []; for (var j = 0; j < this.col; j++) { var spriteFrame = new SpriteFrame(); spriteFrame.texture = this.texture; spriteFrame.rect = new Rect(j * this._pieceWidth, i * this._pieceHeight, this._pieceWidth, this._pieceHeight); spriteFrame.rotated = false; spriteFrame.offset = new Vec2(0, 0); spriteFrame.originalSize = new Size(this._pieceWidth, this._pieceHeight); this._bitmapArr[i][j] = spriteFrame; } } this.m_sprite.spriteFrame = this._bitmapArr[this.rowIndex][0]; this.m_sprite.spriteFrame.width; var uiTransform = this.getComponent(UITransform); if (uiTransform) { uiTransform.width = this._pieceWidth; uiTransform.height = this._pieceHeight; } this.timer = 0; this.running = this.autoPlayOnLoad; } update(dt) { if (!this.running) return; if (this.playTimes != 0 && this.currentTimes == this.playTimes) { this.running = false; return; } this.timer -= dt; if (this.timer <= 0) { this.timer = this.interval; this.currentFrame = this.currentFrame % this.col; this.playAction(); this.currentFrame++; if (this.currentFrame == this.col) { if (this.isAll) { this.rowIndex++; if (this.rowIndex == this.row) { this.currentTimes++; this.node.emit("completeTimes"); if (this.playTimes != 0 && this.currentTimes == this.playTimes) { this.node.emit("complete"); if (this.autoDestroy) { this.node.destroy(); } } } this.rowIndex %= this.row; } else { this.currentTimes++; this.node.emit("completeTimes"); if (this.playTimes != 0 && this.currentTimes == this.playTimes) { this.node.emit("complete"); if (this.autoDestroy) { this.node.destroy(); } } } } } } 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.m_sprite.spriteFrame.setRect(this.rect); this._playIndex++; } /** 播放影片 */ play() { this.running = true; } /** 停止播放影片 */ stop() { this.running = false; } /** * 跳帧播放 * @param frame 帧 */ gotoAndPlay(frame) { this.running = true; this._playIndex = frame; this._playIndex = this.clamp(this._playIndex, 0, this.col - 1); } /** * 跳帧停止 * @param frame 帧 */ gotoAndStop(frame) { this.running = false; this._playIndex = frame; this._playIndex = this.clamp(this._playIndex, 0, this.col - 1); this.m_sprite.spriteFrame = this._bitmapArr[this.rowIndex][this._playIndex]; } clamp(value, minLimit, maxLimit) { if (value < minLimit) { return minLimit; } if (value > maxLimit) { return maxLimit; } return value; } }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "interval", [_dec2], { configurable: true, enumerable: true, writable: true, initializer: function initializer() { return 0.1; } }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "texture", [_dec3], { configurable: true, enumerable: true, writable: true, initializer: function initializer() { return null; } }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "playTimes", [_dec4], { configurable: true, enumerable: true, writable: true, initializer: function initializer() { return 0; } }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "row", [_dec5], { configurable: true, enumerable: true, writable: true, initializer: function initializer() { return 4; } }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "col", [_dec6], { configurable: true, enumerable: true, writable: true, initializer: function initializer() { return 4; } }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "rowIndex", [_dec7], { configurable: true, enumerable: true, writable: true, initializer: function initializer() { return 0; } }), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "isAll", [_dec8], { configurable: true, enumerable: true, writable: true, initializer: function initializer() { return false; } }), _descriptor8 = _applyDecoratedDescriptor(_class2.prototype, "autoPlayOnLoad", [_dec9], { configurable: true, enumerable: true, writable: true, initializer: function initializer() { return true; } }), _descriptor9 = _applyDecoratedDescriptor(_class2.prototype, "autoDestroy", [_dec10], { configurable: true, enumerable: true, writable: true, initializer: function initializer() { return false; } }), _descriptor10 = _applyDecoratedDescriptor(_class2.prototype, "begin", [_dec11], { configurable: true, enumerable: true, writable: true, initializer: function initializer() { return 0; } }), _descriptor11 = _applyDecoratedDescriptor(_class2.prototype, "end", [_dec12], { configurable: true, enumerable: true, writable: true, initializer: function initializer() { return 0; } })), _class2)) || _class)); _cclegacy._RF.pop(); _crd = false; } }; }); //# sourceMappingURL=a499aa9bff2a1818e065dc11bd8ab5f3e352ae6e.js.map