cocos2.X版本lua端使用定时器的方法: 1、 lua端的使用方式: local function timerFun(dt) LuaLog("===================",dt) end local scheduler = CCDirector:sharedDirector():getScheduler() scheduler:scheduleScriptFunc(timerFun,1,false) 2、 C++端的实现: /** The scheduled script callback will be called every 'interval' seconds. If paused is YES,then it won't be called until it is resumed. If 'interval' is 0,it will be called every frame. 如果interval = 0,则每帧都执行 return schedule script entry ID,used for unscheduleScriptFunc(). @js NA */ //返回一个entry ID, 在调用unscheduleScriptEntry函数注销定时器时需要用到。 unsigned int scheduleScriptFunc(unsigned int nHandler,float fInterval,bool bPaused); unsigned int CCScheduler::scheduleScriptFunc(unsigned int nHandler,bool bPaused) { //主要是CCSchedulerScriptHandlerEntry内部实现了lua到C++断的封装和转化,这里就不分析了。 CCSchedulerScriptHandlerEntry* pEntry = CCSchedulerScriptHandlerEntry::create(nHandler,fInterval,bPaused); if (!m_pScriptHandlerEntries) { m_pScriptHandlerEntries = CCArray::createWithCapacity(20); m_pScriptHandlerEntries->retain(); } m_pScriptHandlerEntries->addObject(pEntry); return pEntry->getEntryId(); } /** Unschedule a script entry. * @js NA */ //注销一个定时器回调函数 void unscheduleScriptEntry(unsigned int uScheduleScriptEntryID);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。