1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- /**
- * 战斗倒计时
- */
- const {ccclass, property} = cc._decorator;
- @ccclass
- export default class FCountDown extends cc.Component {
- @property(cc.Label)
- mTime: cc.Label = null;
- public isOver = true;
- /**
- * 开始的时间
- */
- private dtime = 0;
- private totalTime = 0;
- private callback:()=>void;
- onLoad(){
- this.node.active = false;
- }
- public setCallback(callback:()=>void){
- this.callback = callback;
- }
- public startCountDown(totalTime:number){
- this.node.active = true;
- this.totalTime = totalTime;
- this.dtime = new Date().getTime();
- this.isOver = false;
- }
- public stopCountDown(){
- this.node.active = false;
- this.isOver = true;
- }
- /**
- * 暂停住倒计时
- */
- public pauseTime(){
-
- }
- update (dt) {
- if(this.isOver){
- return;
- }
- let nowTime = new Date().getTime();
- let rest = this.totalTime - Math.floor((nowTime - this.dtime)/1000);
- if(rest < 0){
- this.isOver = true;
- this.callback();
- }else{
- this.mTime.string = ''+rest;
- }
- }
- }
|