cocos Creator 倒计时

本文介绍了在Cocos Creator中实现倒计时的三种方法:1) 使用schedule方法配合定时回调更新时间;2) 在update方法中减去时间并更新显示;3) 利用cc.delayTime和cc.callFunc实现倒计时。同时提到了Math.floor、Math.ceil和Math.round等数学方法用于数值处理,以及如何保留小数位数。
摘要由CSDN通过智能技术生成

//倒计时
一 方法1 )
SetCountDownTime(){
let time=5;
let timeCallback=function(dt){
if(time && time>0){
time-=dt;
let _time=Math.ceil(time)
this.setTimeLabel(_time);
if(this.timeNodes&&this.timerNum_label){
this.timerNum_label.string=this._time;
}
}
}
this.schedule(timeCallback,1.0);
if(time<=0){
time=5;
}

    }

二 方法2)
//倒计时
timer:number = 20;
Nexttim:number=0;
update (dt) {
this.timer-=dt;
this.Nexttim= Math.round(this.timer)
cc.find(‘coninue/txt’, this.node).getComponent(cc.Label).string = this.Nexttim.toString();

 }

floor:下退 Math.floor(12.9999) = 12 ceil:上进 Math.ceil(12.1) = 13; round: 四舍五入 Math.round(12.5) = 13 Math.round(12.4) &

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值