import Tween = Laya.Tween;
import { SettingController } from "../../game_logic/SettingController";
export default class ImageRunTime extends Laya.Image {
    public scaleTime: number = 80;
    constructor() {
        super();
        //设置组件的中心点
        this.anchorX = this.anchorY = 0.5;
        this.on(Laya.Event.MOUSE_DOWN, this, this.scaleSmall);
        this.on(Laya.Event.MOUSE_UP, this, this.scaleBig);
        this.on(Laya.Event.MOUSE_OUT, this, this.scaleBig);
    }
    protected _mclickHandler: Function;
    private bigTween: Tween;
    private SmallTween: Tween;
    private clickId=false;
    private scaleBig(e:Laya.Event): void {
        //变大还原的缓动效果
     
        if(!this.clickId)return;
        this.clickId=false;
      
        this.bigTween = Tween.to(this, { scaleX: 1, scaleY: 1 }, this.scaleTime);
        if (this._mclickHandler) {
            this._mclickHandler();
        }
    }
    private scaleSmall(e:Laya.Event): void {
        //缩小至0.8的缓动效果
        SettingController.Instance._Click();
        this.clickId=true;
        this.SmallTween = Tween.to(this, { scaleX: 0.8, scaleY: 0.8 }, this.scaleTime);
    }
    protected ClearRunTime() {
        if (this.bigTween) {
            this.bigTween.clear();
        }
        if (this.SmallTween) {
            this.SmallTween.clear();
        }

        this.off(Laya.Event.MOUSE_DOWN, this, this.scaleSmall);
        this.off(Laya.Event.MOUSE_UP, this, this.scaleBig);
        this.off(Laya.Event.MOUSE_OUT, this, this.scaleBig);
        this._mclickHandler = null;
    }
}