参考计时器的API文档 写了下面的倒计时的实现
var xxxUtils = require("XXUtils");
cc.Class({
extends: cc.Component,
properties: {
level:{
type: cc.Label,
default: null
},
timeDesp:{
type: cc.Label,
default: null
},
timeRemain: 60
},
timeInsufficient: function(){
console.log(" time Insufficient");
},
countDown: function(){
if(this.timeRemain <= 0){
this.timeInsufficient();
this.unschedule(this.countDown);
}
this.timeRemain --;
this.timeDesp.string = xxxUtils.toTimeStr(this.timeRemain);
},
onLoad: function(){
console.log("onload ...");
this.level.string = 2 + "";
this.timeDesp.string = xxxUtils.toTimeStr(this.timeRemain);
component.schedule(this.countDown, 1);
// this.timeDesp.string = "1:00";
},
});
为什么不能用呢? 提示 component不存在