
cc.Class({
    extends: cc.Component,

    properties: {
        FadeTag : null
    },
    start () {
        this.node.setLocalZOrder(999999);
        this.FadeTag = false;//如果灭屏的过程中再来调用，就不给调用了。
    },

    onload : function () {

    },


    FadeInAndOut:function(callbackFadeIn,callbackFadeOut)
    {
        // cc.log("我是shade的FadeInAndOut,我的FadeTag是"+this.FadeTag);

        if (this.FadeTag) {
            return;
        }
        this.node.opacity=0;
        // this.FadeOut(10,function () {
        //
        // }.bind(this));

        this.FadeTag = true;
        this.FadeIn(0.1,function () {
            if (callbackFadeIn != null) {
                callbackFadeIn();
            }else{
            }
            setTimeout(function () {

                this.FadeOut(0.1,function () {
                    this.FadeTag = false;
                    if (callbackFadeOut != null) {
                        callbackFadeOut();
                        // cc.find("TouchLayout").getComponent("NodeTouch").touchClick(true);
                        // cc.eventManager.resumeTarget(cc.find("TouchLayout"),true)
                    }
                }.bind(this));
            }.bind(this),500);
        }.bind(this));


        // this.FadeTag = true;
    },
    // FadeInAndOutControl : function (tag) {
    //     if (tag) {
    //         this.node.opacity+=4;
    //     }else {
    //
    //     }
    // },
    FadeIn:function(duration,fun)
    {
        var rate = duration/255;

        this.schedule(function()
        {
            if(this.node.opacity>=250)
            {
                if(this.node.opacity==255)
                {
                    if(fun!=null)
                    {
                        fun();
                    }
                }
                this.node.opacity =255;

                return;
            }
            this.node.opacity +=5;
        }, rate,51);
    },
    FadeOut:function(duration,fun)
    {
        var rate = duration/255;

        this.schedule(function()
        {
            if(this.node.opacity<=5)
            {
                if(this.node.opacity==0)
                {
                    if(fun!=null)
                    {
                        this.node.opacity =0;
                        fun();
                    }
                }
                this.node.opacity =0;

                return;
            }
            this.node.opacity -=5;
        }, rate,51);
    },
    FadeInCallBack:function()
    {

    },
    FadeOutCallBack:function()
    {

    },
    update :function(dt) {
        // cc.log(this.FadeTag+'******');
        // if (this.FadeTag != null) {
        //     this.FadeInAndOutControl(this.FadeTag);
        // }

    },
});
