//文件名:Timer
cc.Class({
extends: cc.Component,
properties: {
TimeLabel: cc.Label,
},
// LIFE-CYCLE CALLBACKS:
onLoad() {
this.Timer();
this.reSetTime();
this.startTimer();
},
start() {
},
//计时器
Timer: function () {
this.schedule(function () {
if (this.timer > 0 && this.timeron) {
this.timer--;
this.TimeLabel.string = this.timer;
}
else if (this.timer === 0) {
//回合操作
this.timer = -1;
}
}, 1);
},
reSetTime: function () {
this.timeron = false;
this.timer = this.huiheTime;
this.TimeLabel.string.string = this.huiheTime;
},
startTimer() {
setTimeout(function () {
this.timeron = true;
}.bind(this), 500); },
stopTimer() {
this.timeron = false;
},
// update (dt) {},
});
使用:
require(“Timer”).Instance().startTimer();