"use strict";
var __reflect = (this && this.__reflect) || function (p, c, t) {
    p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t;
};
var __extends = this && this.__extends || function __extends(t, e) { 
 function r() { 
 this.constructor = t;
}
for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]);
r.prototype = e.prototype, t.prototype = new r();
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * 直接通过替换source替换图片的动画帧
 * 暂时这些动画帧只播放一次，所以简化
 * 默认按时间间隔播放
 * 图片都以素材为中心为原点
 */
var ImageAni = (function (_super) {
    __extends(ImageAni, _super);
    /**
     *
     * @param sourceAll 所有的资源数组
     */
    function ImageAni(sourceAll) {
        var _this = _super.call(this) || this;
        //需要做锁步
        _this.count = 0;
        _this.sourceAll = sourceAll;
        _this.texture = RES.getRes(sourceAll[0]);
        // this.source = sourceAll[0];
        // this.x = -this.texture.textureWidth / 2;
        // this.y = -this.texture.textureHeight / 2;
        _this.currentFrame = 0;
        _this.totalFrames = sourceAll.length;
        _this.addEventListener(egret.Event.ENTER_FRAME, _this.onEnterFrame, _this);
        _this.allTime = _this.sourceAll.length / 20 * 1000;
        return _this;
    }
    ImageAni.prototype.onEnterFrame = function () {
        if (!this.isPlay) {
            // this.count = 0
            return;
        }
        // this.count++;
        // if (this.count % 2 == 0) {
        //     this.currentFrame++;
        //     if (this.currentFrame == this.totalFrames/*-1*/) {
        //         this.currentFrame = 0;
        //         this.isPlay = false
        //         this.callback && this.callback();
        //     }
        //     this.texture = RES.getRes(this.sourceAll[this.currentFrame])
        //     this.x = -this.texture.textureWidth / 2;
        //     this.y = -this.texture.textureHeight / 2;
        // }
        var dataNow = Date.now();
        var deltaTime = dataNow - this.startTime;
        var scale = deltaTime / this.allTime;
        if (scale >= 1) {
            this.isPlay = false;
            this.callback && this.callback();
            //重复播放
            this.play();
        }
        else {
            this.currentFrame = (scale * this.sourceAll.length) >> 0;
            this.texture = RES.getRes(this.sourceAll[this.currentFrame]);
            // this.x = -this.texture.textureWidth / 2;
            // this.y = -this.texture.textureHeight / 2;
        }
    };
    /**
     * 从0开始播
     * 回调是播放完后做回收用的
     */
    ImageAni.prototype.play = function (callback) {
        this.startTime = Date.now();
        this.isPlay = true;
        this.currentFrame = 0;
        this.texture = RES.getRes(this.sourceAll[this.currentFrame]);
        // this.x = -this.texture.textureWidth / 2;
        // this.y = -this.texture.textureHeight / 2;
        this.callback = callback;
    };
    /**
     * 啥特效就是啥
     */
    ImageAni.prototype.reset = function () {
        this.isPlay = false;
        this.currentFrame = 0;
        this.texture = RES.getRes(this.sourceAll[0]);
        this.x = -this.texture.textureWidth / 2;
        this.y = -this.texture.textureHeight / 2;
    };
    return ImageAni;
}(eui.Image));
exports.ImageAni = ImageAni;
__reflect(ImageAni.prototype, "\"/Users/zuopeng/DBGitLab/db-game-template/egret/src/panels/ImageAni\".ImageAni");
//# sourceMappingURL=ImageAni.js.map