第十五节cocosdx的定时器
来源:互联网 发布:有向图自动布局算法 编辑:程序博客网 时间:2024/06/05 00:04
定时器分析:
CCNode 里面有相关接口,主要为每一帧刷新以及定时刷新:
每一帧刷新:
scheduleupdate();
然后实现:
void XXX::update(float fDelta)
{
CCNode::update(fDelta);
自己的代码
}
定时代码为:
void CCNode::schedule(SEL_SCHEDULE selector)// 一直调用
void CCNode::schedule(SEL_SCHEDULE selector, float interval)// 传入调用间隔
void CCNode::schedule(SEL_SCHEDULE selector, float interval, unsigned int repeat, float
delay)
// 传入调用间隔重复次数以及重复之间的间隔
void CCNode::scheduleOnce(SEL_SCHEDULE selector, float delay)
调用一次函数
其中typedef void (CCObject::*SEL_SCHEDULE)(float);
我们使用#define schedule_selector(_SELECTOR) (SEL_SCHEDULE)(&_SELECTOR)来进行操作。
void CCNode::unschedule(SEL_SCHEDULE selector)
撤掉对应的定时器。
CCNode::unscheduleUpdate();
撤掉每帧更新的定时器。
onenter 里面调用:
resumeSchedulerAndActions();
onexit 里面调用:
pauseSchedulerAndActions();
在更换定时器调度实例时调用:
unscheduleAllSelectors();
接着我们跟踪下schedule 函数。
m_pScheduler->scheduleSelector(selector, this, interval , repeat, delay, !m_bRunning);
里面主要做几件事情:
查找一个存储列表,申请一个CCTimer,存储下时间,回调函数,注册在
ccArrayAppendObject(pElement->timers, pTimer);
这里面。
里面如果回调函数一致,则会修改回调时间,直接就可以返回了。
调度器:
CCScheduler.cpp 里面的update 函数会在CCDirector.cpp 里面的drawScene 里面调用。
drawScene 函数会在CCDisplayLinkDirector::mainLoop(void)里面调用,mainloop 会在每一帧进
行调用。
回到CCScheduler::update(float dt)里面来,df 这个值为时间流逝值
if (m_fTimeScale != 1.0f)
{
dt *= m_fTimeScale;
}
这里的m_fTimeScale 可以实现加速减速。
然后执行代码为
1>更新每帧的update,优先顺序为<0, =0,>0.
2>刷新所有的定时器
for (tHashTimerEntry *elt = m_pHashForTimers; elt != NULL; )
{
m_pCurrentTarget = elt;
m_bCurrentTargetSalvaged = false;
if (! m_pCurrentTarget->paused)
{
// The 'timers' array may change while inside this loop
for (elt->timerIndex = 0; elt->timerIndex < elt->timers->num;
++(elt->timerIndex))
{
elt->currentTimer = (CCTimer*)(elt->timers->arr[elt->timerIndex]);
elt->currentTimerSalvaged = false;
elt->currentTimer->update(dt);
if (elt->currentTimerSalvaged)
{
// The currentTimer told the remove itself. To prevent the timer from
// accidentally deallocating itself before finishing its step, we retained
// it. Now that step is done, it's safe to release it.
elt->currentTimer->release();
}
elt->currentTimer = NULL;
}
}
3>脚本时间回调,我们不需要关注,因为我们开发的是android 版本。
4>回收标记过时的timer
这里我们没有看到action 动作执行过程,那么我们继续跟踪:
在CCDirector::init(void)里面:
m_pActionManager = new CCActionManager();
m_pScheduler->scheduleUpdateForTarget(m_pActionManager, kCCPrioritySystem,
false);
这里可以看到action 动作是注册在Scheduler 里面的,所以之前的
CCScheduler::update(float dt)里面是处理了action 动作执行了。
本节收尾,下节继续分析,跟踪下一个CCActionManager 管理的Action。
CCNode 里面有相关接口,主要为每一帧刷新以及定时刷新:
每一帧刷新:
scheduleupdate();
然后实现:
void XXX::update(float fDelta)
{
CCNode::update(fDelta);
自己的代码
}
定时代码为:
void CCNode::schedule(SEL_SCHEDULE selector)// 一直调用
void CCNode::schedule(SEL_SCHEDULE selector, float interval)// 传入调用间隔
void CCNode::schedule(SEL_SCHEDULE selector, float interval, unsigned int repeat, float
delay)
// 传入调用间隔重复次数以及重复之间的间隔
void CCNode::scheduleOnce(SEL_SCHEDULE selector, float delay)
调用一次函数
其中typedef void (CCObject::*SEL_SCHEDULE)(float);
我们使用#define schedule_selector(_SELECTOR) (SEL_SCHEDULE)(&_SELECTOR)来进行操作。
void CCNode::unschedule(SEL_SCHEDULE selector)
撤掉对应的定时器。
CCNode::unscheduleUpdate();
撤掉每帧更新的定时器。
onenter 里面调用:
resumeSchedulerAndActions();
onexit 里面调用:
pauseSchedulerAndActions();
在更换定时器调度实例时调用:
unscheduleAllSelectors();
接着我们跟踪下schedule 函数。
m_pScheduler->scheduleSelector(selector, this, interval , repeat, delay, !m_bRunning);
里面主要做几件事情:
查找一个存储列表,申请一个CCTimer,存储下时间,回调函数,注册在
ccArrayAppendObject(pElement->timers, pTimer);
这里面。
里面如果回调函数一致,则会修改回调时间,直接就可以返回了。
调度器:
CCScheduler.cpp 里面的update 函数会在CCDirector.cpp 里面的drawScene 里面调用。
drawScene 函数会在CCDisplayLinkDirector::mainLoop(void)里面调用,mainloop 会在每一帧进
行调用。
回到CCScheduler::update(float dt)里面来,df 这个值为时间流逝值
if (m_fTimeScale != 1.0f)
{
dt *= m_fTimeScale;
}
这里的m_fTimeScale 可以实现加速减速。
然后执行代码为
1>更新每帧的update,优先顺序为<0, =0,>0.
2>刷新所有的定时器
for (tHashTimerEntry *elt = m_pHashForTimers; elt != NULL; )
{
m_pCurrentTarget = elt;
m_bCurrentTargetSalvaged = false;
if (! m_pCurrentTarget->paused)
{
// The 'timers' array may change while inside this loop
for (elt->timerIndex = 0; elt->timerIndex < elt->timers->num;
++(elt->timerIndex))
{
elt->currentTimer = (CCTimer*)(elt->timers->arr[elt->timerIndex]);
elt->currentTimerSalvaged = false;
elt->currentTimer->update(dt);
if (elt->currentTimerSalvaged)
{
// The currentTimer told the remove itself. To prevent the timer from
// accidentally deallocating itself before finishing its step, we retained
// it. Now that step is done, it's safe to release it.
elt->currentTimer->release();
}
elt->currentTimer = NULL;
}
}
3>脚本时间回调,我们不需要关注,因为我们开发的是android 版本。
4>回收标记过时的timer
这里我们没有看到action 动作执行过程,那么我们继续跟踪:
在CCDirector::init(void)里面:
m_pActionManager = new CCActionManager();
m_pScheduler->scheduleUpdateForTarget(m_pActionManager, kCCPrioritySystem,
false);
这里可以看到action 动作是注册在Scheduler 里面的,所以之前的
CCScheduler::update(float dt)里面是处理了action 动作执行了。
本节收尾,下节继续分析,跟踪下一个CCActionManager 管理的Action。
- 第十五节cocosdx的定时器
- 第十一节cocosdx的内存管理机制
- 第十三节cocosdx的按键增加过程
- 第五节 定时器使用
- php学习 第十五节
- java第十五节-泛型
- 第十五节,Promise对象
- 第十五节:调用JS
- 第十五节:矩阵键盘单个触发的压缩代码编程
- 第十五节Map和File
- Java基础部分第十五节
- 汇编第十五节-外中断
- cocosdx 游戏开发的主要要求
- 第十四节cocosdx的声音接口
- cocosdx 关于CCSpriteFrameCache::sharedSpriteFrameCache()的问题
- 第十五节--Zend引擎的发展 -- Classes and Objects in PHP5 [15]
- [ExtJS5学习笔记]第十五节 Extjs5表格显示不友好?panel的frame属性在作怪
- 第十五节 java学习 for循环语句
- 用递归法将一个整数n转化成字符串
- 第十四节cocosdx的声音接口
- 文件操作
- 如何对php网站进行301重定向
- USB描述符详解
- 第十五节cocosdx的定时器
- dos窗口下删除.svn文件的命令
- 【第七课:C++和opencv】图像的膨胀+控制条
- 第十六节自动配置cpp文件的mk
- 配置和自动启动Oracle的监听(lsnrctl)
- 对于循环不变式证明的总结
- PreTranslateMessage作用和使用方法
- nm命令
- 经典SQL语句大全