export class LightComponent extends eui.Component{

    public image:eui.Image;
    public image5:eui.Image;
    public image7:eui.Image;
    public image6:eui.Image;
    public image0:eui.Image;
    public image1:eui.Image;
    public image2:eui.Image;
    public image3:eui.Image;
    public image4:eui.Image;
    

   
    //点击收取回调
    private clickCallBack:Function;
    r_width
    r_height
    r_x
    r_y
    lv
    /**
     * 
     */
    constructor(lv,width,height,x,y,callBack:Function = null){
        super();
        this.skinName       = 'resource/skins/item/lightSkin.exml';
        this.clickCallBack  = callBack;
        this.r_width=width;
        this.r_height=height;
        this.r_x=x;
        this.r_y=y;
        this.lv=lv
       
        this.addEventListener(egret.Event.COMPLETE, this.onSkinComplete, this);
        //if (this.skin) {
            this.onSkinComplete();
       // }
    }

    private onSkinComplete():void{
        //this.image.visible=false;
        // setTimeout(()=>{
        //     this.image.visible=true;
        //     this["loop"].play(0)
        //     this["loop"].items.forEach((item) => {
        //         item.tween.loop = true;
        //     })
        // },1000*Math.random())
        this.setAnimate()
        this.removeEventListener(egret.Event.COMPLETE, this.onSkinComplete, this);
    }

    setAnimate(){
        // var tw = egret.Tween.get( target );
        // tw.to( {x:1500}, 1000 );
       // alert(this.lv)
        let setLightCount=0
        if(this.lv==1){
            setLightCount=0
        }else if(this.lv==2){
            setLightCount=2
        }else if(this.lv==3){
            setLightCount=4
        }else if(this.lv==4){
            setLightCount=6
        }else if(this.lv==5){
            setLightCount=7
        }

        alert(this.lv)

        let maxLight=this.lv*0.05+1;
        let minLioght=1;

        var tw = egret.Tween.get( this.image, { loop:true} );
        tw.set( {scaleX:minLioght,scaleY:minLioght,alpha:.5})  
        .wait( 1000*Math.random() )
        .to( {scaleX:maxLight,scaleY:maxLight,alpha:1}, 1000 )
        .to( {scaleX:minLioght,scaleY:minLioght,alpha:.5}, 1000 )  
        for(let i=0;i<8;i++){
            this[`image${i}`].visible=true;
        }
        for(let i=0;i<8;i++){
            this.rotation=Math.random()*360;
            //this[`image${i}`].visible=false;
           // this[`image${i}`].x=this.r_x+this.r_width*Math.random();
           // this[`image${i}`].y=this.r_y+this.r_height*Math.random();
            var tw = egret.Tween.get( this[`image${i}`], { loop:true} );
            tw.set( {scaleX:.6,scaleY:.6,alpha:.5})  
            .wait( 1000*Math.random() )
            .to( {scaleX:1,scaleY:1,alpha:1}, 1000 )
            .to( {scaleX:.6,scaleY:.6,alpha:.5}, 1000 )  
            if(i>setLightCount){
                this[`image${i}`].visible=false;
            }else{
                //this[`image${i}`].visible=true;
            }
        }
        
    }

    public removeEvent():void{

    }

    private onClick():void{
        if(this.clickCallBack){
            this.clickCallBack(this);
        }
    }
    
    public playAct(start:number = 0):void{
        
    }

    public stopAct():void{
        // this.act.stop();
    }
}