"use strict";
cc._RF.push(module, 'c16cfCLFXZE2K3H5EtA4alm', 'item');
// scripts/prefabTest/item.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var prefabTestGameData_1 = require("./prefabTestGameData");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var item = /** @class */ (function (_super) {
    __extends(item, _super);
    function item() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this._clip = null;
        _this._sp = null;
        _this._spArr = [];
        return _this;
    }
    item.prototype.onLoad = function () {
        // this.loopPlay();
    };
    item.prototype.createGif = function (num) {
        var key = prefabTestGameData_1.preGameData.zipData.gifMap.getKey(num);
        var t_frames = prefabTestGameData_1.preGameData.zipData.gifMap.get(key);
        if (this._clip) {
            this._clip.decRef();
            this._clip.destroy();
            this._clip = null;
        }
        this._clip = cc.AnimationClip.createWithSpriteFrames(t_frames, t_frames.length);
        this._clip.name = "anim";
        this._clip.sample = 60;
        this._clip.speed = 0.4;
        this._clip.wrapMode = cc.WrapMode.Loop;
        this._clip.addRef();
        var sp = this.node.getComponent(cc.Sprite);
        sp.spriteFrame = null;
        var anim = this.node.getComponent(cc.Animation);
        if (!anim) {
            anim = this.node.addComponent(cc.Animation);
        }
        anim.addClip(this._clip);
        anim.play("anim");
        //另外一种动画播放方案
        // this.playAnim(num);
    };
    // playAnim(num) {
    //     let key = preGameData.zipData.gifMap.getKey(num);
    //     this._spArr = preGameData.zipData.gifMap.get(key);
    //     this._sp = this.node.getComponent(cc.Sprite);
    // }
    // loopPlay(num: number = 0) {
    //     if (this._spArr.length > 0) {
    //         if (num >= this._spArr.length) {
    //             num = 0;
    //         }
    //         this._sp.spriteFrame = this._spArr[num];
    //         this.scheduleOnce(() => {
    //             num++
    //             this.loopPlay(num);
    //         }, 0.1)
    //     } else {
    //         this.scheduleOnce(() => {
    //             this.loopPlay();
    //         }, 0.5);
    //     }
    // }
    /**清除数据 */
    item.prototype.clearData = function () {
        this._spArr = [];
        var anim = this.node.getComponent(cc.Animation);
        if (anim) {
            anim.stop();
            anim.destroy();
            // this.node.removeComponent(cc.Animation);
        }
        // let sp = this.node.getComponent(cc.Sprite);
        // sp.spriteFrame = null;
        if (this._clip) {
            this._clip.decRef();
            cc.log("--clip-->>>", this._clip.refCount);
            this._clip.destroy();
            this._clip = null;
        }
    };
    item.prototype.removeNode = function () {
        this.node.destroy();
    };
    item = __decorate([
        ccclass
    ], item);
    return item;
}(cc.Component));
exports.default = item;

cc._RF.pop();