最近在学习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;