laya实现倒计时

本文介绍了作者在学习Laya框架过程中,如何实现倒计时功能,包括普通倒计时和00:00:00格式的倒计时实现细节,适合Laya初学者参考。
摘要由CSDN通过智能技术生成

最近在学习Laya相关的知识,其中就涉及到了倒计时相关的部分,由于本人是新手,所以花费了很多时间去实现这个东西:

普通的倒计时:

export default class tCount extends Laya.Script {
    [x: string]: any;
    nCountDown: number;
    txt_TimeCountDown: any;

    /** @prop {name:txt_TimeCountDown, tips:"倒计时", type:Node, default:1000}*/
    // 更多参数说明请访问: https://ldc2.layabox.com/doc/?nav=zh-as-2-4-0

    constructor() { 
        super(); 
        this.txt_TimeCountDown=null;
          
    }

    onAwake(){
        console.log("GameManager onAwake");
        
        
    }
   onStart(){
    this.gameStart();
   }
    onEnable(): void {
    }

    onDisable(): void {
    }

    onSecond(){
        this.nCountDown--;
        this.txt_TimeCountDown.text=""+this.nCountDown;
        if(this.nCountDown<=0){
            this.gameOver();
            console.log("游戏结束");   
        }
    }

    gameStart(){
    
        this.nCountDown=100;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值