Laya 技能CD冷却效果

 

/*
* 技能CD冷却;
*/
var skillBtn = (function(_super) {
    function skillBtn(params) {
        skillBtn.super(this);
        this.maxAngle = 360
        this.angle = 0;
        this.start = 0;
        this.skin = params.imgPath; 
        this.pos(params.x,params.y) 
        if(!params.parent){
            console.log("not find parent Node")
            return
        } 
        var parent  = params.parent
        parent.addChild(this); 
        this.bg = new Laya.Image();
        this.bg.skin = params.imgPath;
        this.bg.pos(params.x,params.y) 
        var sp = new Laya.Sprite();
        parent.addChild(this.bg);
        this.bg.mask = sp;
        this.bg.visible = false;
        this.spMask = sp; //用作画笔
    }

    Laya.class(skillBtn,"skillBtn",_super)
    var _proto_ = skillBtn.prototype;
 
    _proto_.setCdTime = function(cdTime){
        //cd 时间
         this.cdTime = cdTime
    }

    _proto_.startT = function(){ 
        //释放技能时间
        this.tickTime = new Date().getTime() 
        //总恢复真实时间
        this.totalTime = this.tickTime + this.cdTime*1000
        //剩余倒计时时间
        this.retime = Math.ceil((this.totalTime - new Date().getTime())/1000)
        //已经使用时间
        this.useTime = this.cdTime - this.retime
        //恢复已经计时的
        this.angle += Math.ceil((this.maxAngle/this.cdTime)*this.useTime);
 
        if(this.retime < 0){
            return; 
        } 
        this.gray = true
        this.bg.visible = true;
        this.spMask.graphics.drawPie(this.bg.width/2, this.bg.height/2, this.bg.width/2, this.start, this.angle, "#ffffff");
        Laya.timer.frameLoop(1, this, this._startCd.bind(this));
    }
 
    /**
    * 开始倒计时CD
    */
    _proto_._startCd = function(){
        if (this.angle >= this.maxAngle) {
            this._endCD()
            return;
        }
        this.angle += (Laya.timer.delta/1000)*(360/this.retime); 
        console.log(this.angle)
        this.spMask.graphics.clear();
        this.spMask.graphics.drawPie(this.bg.width/2, this.bg.height/2, this.bg.width/2,         
        this.start, this.angle, "#ffffff");
    }

    /**
    * 结束倒计时
    */
    _proto_._endCD = function(){ 
        Laya.timer.clearAll(this);
        this.angle = 0
        this.gray = false
        this.bg.visible = false;  
    }
    return skillBtn;
}(Laya.Image));

 //使用只需要
var params = { 
    parent:Laya.stage,
    x:100,
    y:100,
    imgPath: "common/skill.png"  
}
var skillBtn = new skillBtn( params );
skillBtn.setCdTime(10)//设置CD时长 秒
skillBtn.startT();

 

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值