quick cocos2dx 定时器

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. function MainScene:ctor()  
  2.     self.scheduler = require('framework.scheduler')            -- 定义一个定时器  
  3.     self.handler = self.scheduler.scheduleGlobal(function()    -- 这里必须如此定义,否则self内的成员不可用,返回一个全局的定时器handler,用来取消定时  
  4. self:OnTimer()  
  5. end, 1)  -- 每秒回调一次self.OnTimer函数  
  6.   
  7.     self.lab = cc.ui.UILable.new({UILabelType = 2, text = 'now', size = 64})  -- 一个lable控件  
  8. :align(display.CENTER, display.cx, display.cy)  
  9. :addTo(self)  
  10. end  
  11.   
  12. function MainScene:OnTimer()                     --   
  13.     loacl data = os.date('%H:%M:%S')  
  14.     self.lab:setString(data)  
  15.     -- self.scheduler.unscheduleGlobal(self.handler)  -- 此行取消注释的话可停止该定时器  
  16. end  

在lua中使用一个定时器的demo,基于quick cocos2dx 3.x版本。

需要注意的是,function的格式必须是这样子的,而不能是以下的形式:

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. self.handler = self.scheduler.scheduleGlobal(self.OnTimer(), 1)  

若是这样子定义的话,在OnTimer里面的self是不能被识别的。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值