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;
            }
        }

    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM