cocos2dx-js 定时器

原文: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);
     }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值