原文:http://www.cocoachina.com/bbs/read.php?tid-230933.html
宋宋说让我回家,就不写太多了~~~
定时器schedule、 scheduleOnec、scheduleUpdate
需要注意的是用该方法的地方首先需要把代码跑起来,可以调用它的
1
|
this
.isRunning();
|
打印该值看是否已经跑起来了。
schedule:自定义回调函数名字,第二个参数是每格多久执行一次,如果为0表示每帧执行,建议适用scheduleUpdate()
1
2
3
4
5
6
7
8
|
onEnter:
function
(){
this
._super();
this
.schedule(
this
.scheduleCallFun, 3, cc.REPEAT_FOREVER, 5);
},
scheduleCallFun:
function
(){
cc.log(
"---scheduleCallFun---"
);
}
|
scheduleUpdate:每帧自动执行update()方法,所以需要自己实现update()。
1
2
3
4
5
6
7
8
|
onEnter:
function
(){
this
._super();
this
.scheduleUpdate();
},
update:
function
(dt){
cc.log(
" --- update ---"
);
}
|
scheduleOnec: 顾名思义是只执行一次,需要注意的是传进去的时间单位是秒。
例如 :5秒后执行一次方法
1
2
3
4
5
6
|
onEnter:
function
(){
this
._super();
this
.scheduleOnce(
function
(){
cc.log(
"---scheduleOnce----"
);
}, 5);
}
|