cocos2dx定时器详解
来源:互联网 发布:mac os x10.10.5 编辑:程序博客网 时间:2024/05/16 17:43
cocos2dx定时器详解
前言
最近一直在忙cocos2d的Android端游戏,作为从零基础直接上手的菜鸟真的有很多话要说,但在这里,就长话短说了,C++真的是一门有优秀的语言,但是精通好像还蛮难的,我这边的项目需求是用户点击广告,暂时将未解锁的人物角色解锁15分钟供用户使用。这在cocos2d里其实就是用到的是CCSchedule和CCNode类,这个需要结合cocos2d的源码进行分析就会比较简单了。
源码分析
以下是设置定时器
void CCNode::schedule(SEL_SCHEDULE selector){ this->schedule(selector, 0.0f, kCCRepeatForever, 0.0f);}void CCNode::schedule(SEL_SCHEDULE selector, float interval){ this->schedule(selector, interval, kCCRepeatForever, 0.0f);}void CCNode::schedule(SEL_SCHEDULE selector, float interval, unsigned int repeat, float delay){ CCAssert( selector, "Argument must be non-nil"); CCAssert( interval >=0, "Argument must be positive"); m_pScheduler->scheduleSelector(selector, this, interval , repeat, delay, !m_bRunning);}//设置一次性的定时器void CCNode::scheduleOnce(SEL_SCHEDULE selector, float delay){ this->schedule(selector, 0.0f, 0, delay);}
取消定时器
void CCNode::unschedule(SEL_SCHEDULE selector){ // explicit nil handling if (selector == 0) return; m_pScheduler->unscheduleSelector(selector, this);}//取消所有的定时器void CCNode::unscheduleAllSelectors(){ m_pScheduler->unscheduleAllForTarget(this);}
更新定时器
void CCNode::scheduleUpdate(){ scheduleUpdateWithPriority(0);}void CCNode::scheduleUpdateWithPriority(int priority){ m_pScheduler->scheduleUpdateForTarget(this, priority, !m_bRunning);}void CCNode::scheduleUpdateWithPriorityLua(int nHandler, int priority){ unscheduleUpdate(); m_nUpdateScriptHandler = nHandler; m_pScheduler->scheduleUpdateForTarget(this, priority, !m_bRunning);}
取消更新定时器
//void CCNode::unscheduleUpdate(){ m_pScheduler->unscheduleUpdateForTarget(this); if (m_nUpdateScriptHandler) { CCScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(m_nUpdateScriptHandler); m_nUpdateScriptHandler = 0; }}
暂停定时器和动作
void CCNode::pauseSchedulerAndActions(){ m_pScheduler->pauseTarget(this); m_pActionManager->pauseTarget(this);}
恢复定时器和动作
void CCNode::resumeSchedulerAndActions(){ m_pScheduler->resumeTarget(this); m_pActionManager->resumeTarget(this);}
代码实例
其实源码分析的比较简单,但是大概知道了那几个方法,其实就知道怎么用了,在实例中,是直接让那个类继承CCNode类,所以是直接调用里面的方法的,代码没整理全,明天补上
总结
阅读全文
0 0
- cocos2dx定时器详解
- cocos2dx 定时器
- Cocos2dx 定时器
- cocos2dx 定时器
- cocos2dx 定时器
- Cocos2dx的定时器
- Cocos2dx 定时器schedule
- quick cocos2dx 定时器
- cocos2dx定时器时间不准
- cocos2dx 实现全局定时器
- cocos2dx 全局定时器
- cocos2dx之定时器
- cocos2dx三种定时器
- quick cocos2dx 定时器
- cocos2dx--定时器封装
- cocos2dx Lua 定时器
- cocos2dx定时器的用法
- [windows+cocos2dx]定时器的使用
- python使用socket实现多线程端口扫描
- LeetCode 37. Sudoku Solver
- http协议:http协议理解
- CSDN博客添加自定义栏目
- samba安装配置《一》
- cocos2dx定时器详解
- 51nod 1184 第N个质数(二分+大区间求素数模板)
- 计算圆柱体体积
- AndroidStudio接入信鸽推送常见问题(附安卓接入视频教程)
- 泡妞秘籍总结三
- Android Studio——TODO功能
- hibernate一对多的关系映射
- Mac 使用 扫描 仪
- 完数查找