脚本定时器
1、添加脚本定时器 /** 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. return schedule script entry ID,used for unscheduleScriptFunc(). @js NA */ //供脚本lua使用的定时器函数 unsigned int scheduleScriptFunc(unsigned int nHandler,float fInterval,bool bPaused); -->>源码: unsigned int CCScheduler::scheduleScriptFunc(unsigned int nHandler,bool bPaused) { //CCSchedulerScriptHandlerEntry类在CCScriptSupport中 CCSchedulerScriptHandlerEntry* pEntry = CCSchedulerScriptHandlerEntry::create(nHandler,fInterval,bPaused); if (!m_pScriptHandlerEntries) { m_pScriptHandlerEntries = CCArray::createWithCapacity(20); m_pScriptHandlerEntries->retain(); } //CCArray* m_pScriptHandlerEntries,脚本定时器的数组 m_pScriptHandlerEntries->addObject(pEntry); return pEntry->getEntryId(); } 2、移除脚本定时器 /** Unschedule a script entry. * @js NA */ void unscheduleScriptEntry(unsigned int uScheduleScriptEntryID); -->> void CCScheduler::unscheduleScriptEntry(unsigned int uScheduleScriptEntryID) { for (int i = m_pScriptHandlerEntries->count() - 1; i >= 0; i--) { CCSchedulerScriptHandlerEntry* pEntry = static_cast<CCSchedulerScriptHandlerEntry*>(m_pScriptHandlerEntries->objectAtIndex(i)); if (pEntry->getEntryId() == (int)uScheduleScriptEntryID) { //只是设置了移除标志,并没有真正移除,真正的移除在其他地方 pEntry->markedForDeletion(); break; } } }原文链接:https://www.f2er.com/cocos2dx/343744.html