zoukankan      html  css  js  c++  java
  • Egret引擎的常用倒计时

    直接上代码,

    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;
                }
            }
    
        }
  • 相关阅读:
    20210309-2 阅读任务
    20210309-1 准备工作
    课程总结
    第十四周课程总结&实验报告(简单记事本的实现)
    十三周课程总结
    十二周课程总结
    第十一周课程总结
    C语言ll作业01
    C语言寒假大作战04
    C语言寒假大作战03
  • 原文地址:https://www.cnblogs.com/allyh/p/10434251.html
Copyright © 2011-2022 走看看