我刚刚做了一个简单的coco2d-x项目. 它有几个场景,每个人都有自己的JavaScript.
dashboard.js
const MyClass = cc.Class.extend({
...
update: function() {
this.remainTimes --;
},
// Call the schedule method in your class constructor or init method
ctor: function() {
// Schedule the update function to be called every frame
this.schedule(this.update().bind(this), 1);
label.setFontFillColor(this.remainTimes);
cc.log('remainTimes : ', this.remainTimes);
};
});
以下是控制台日志(log):
remainTimes : 10
remainTimes : 9
remainTimes : 8
remainTimes : 7
...
但LABEL的文本在1之后是10
,在1之后是6
...
我在找这个dashboard.js是不是在dashboard.scene被呼叫了两次,但没有!
有时它的工作正常,但有时它的工作错误…… 为什么?
我解决了这个问题,并想表明正确的剩余时间.