首页 > 其他 > 详细

Egret引擎的常用倒计时

时间:2019-02-25 22:29:12      阅读:275      评论:0      收藏:0      [点我收藏+]

直接上代码,

private timeControl() { 
        let timer: egret.Timer = segret.Timer(1000);
        timer.addEventListener(egret.TimerEvent.TIMER,(event:egret.TimerEvent) =>{
            this.countTotalTime--;
            if(this.countTotalTime < 0){
                //this.countDownShow.text = "0";
                return;
            }
            this.countDownShow.text= this.countTotalTime.toString();
        }, this);
        timer.start();
         
    }

二、
var count:number = 60;
var timer:egret.Timer = new egret.Timer(1000,60);//1000代表1秒执行一次,60代表执行60次,这样实现的一分钟计时
timer.addEventListener(egret.TimerEvent.TIMER,onTimer,this);
timer.addEventListener(egret.TimerEvent.TIMER_COMPLETE,onTimerComplete,this);
timer.start();
function onTimer(evt:egret.TimerEvent):void {
        count--;
        console.log("倒计时:"+count);
}
function onTimerComplete(evt:egret.TimerEvent):void {
        console.log("结束");
}
三、
public countDownShow: eui.Label;
private timer;
private timeControl(second) {
    if (second > 0) {
        this.countDownShow.visible = true;
        this.timer = egret.setInterval(function () {
            if (second > 1) {
                second--;
                this.countDownShow.text = second.toString();
                }
            }, this, 1000);
            if (second <= 1) {
                console.log("停止计时");
                clearInterval(this.timer);
                this.countDownShow.visible = false;
            }
        }

    }

 

Egret引擎的常用倒计时

原文:https://www.cnblogs.com/allyh/p/10434251.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!