schedule怎么用?

就是要显示一个不断跳动的当前时间。

var now;
var UI = {
ready:function(){
this.schedule(UI.update,0.01);
},
update:function(){
now = new Date;
}
}
var GameLayer = cc.Layer.extend({
onEnter: function() {
UI.ready;
var timelb = cc.LabelTTF.create( now , “宋体”, 18, cc.size(180, 180), cc.TEXT_ALIGNMENT_LEFT);
timelb.x = 100;
timelb.y = 80;
timelb.color = cc.color(255, 0, 0);
this.addChild(timelb,10);
}
}:wink:
是这么用的么?

now = new Date;:9:
逻辑混乱。
update函数,感觉没有写完…

var timelb = cc.LabelTTF.create( now , “宋体”, 18, cc.size(180, 180), cc.TEXT_ALIGNMENT_LEFT);
这执行了一次,所以你的now不管怎么变化,都与timelb没有任何关系。

而且 this.schedule是cc.Node的内置函数, 你的UI对象是没有这个功能的。

实现起来非常简单:

var GameLayer = cc.Layer.extend({
onEnter: function() {
var timelb = cc.LabelTTF.create( new Date().toLocaleString(), “宋体”, 18, cc.size(180, 180), cc.TEXT_ALIGNMENT_LEFT);
timelb.x = 100;
timelb.y = 80;
timelb.color = cc.color(255, 0, 0);
this.addChild(timelb,10);
this.schedule(function(){
timelb.setString(new Date().toLocaleString());
}, 1); //1秒更新一次
}
}:wink:

非常感谢!!!