
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); 总结 以上是内存溢出为你收集整理的cocos2.X版本lua端使用定时器的方法全部内容,希望文章能够帮你解决cocos2.X版本lua端使用定时器的方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)