CCNode 的onEnter函数何时调用分析
2015-04-01 17:29
162 查看
从源码中也看到,如CCLayer::onEnter()中注册触摸事件,那么CCNode的onEnter函数是在什么时候调用的呢? 下面从源码角度分析下: /** * Adds a child to the container with z order and tag * * If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately. * * @param child A child node * @param zOrder Z order for drawing priority. Please refer to setZOrder(int) * @param tag A interger to identify the node easily. Please refer to setTag(int) */ //看上面的注释就可以清楚的知道,当我们当前的Node处于running时,那么添加到其上的 //子Node,会立即执行onEnter和onEnterTransitionDidFinish virtual void addChild(CCNode* child, int zOrder, int tag); -->> void CCNode::addChild(CCNode *child, int zOrder, int tag) { ..... if( m_bRunning ) { child->onEnter(); child->onEnterTransitionDidFinish(); } } 假如我们有三级Node,第三级加到第二级上时,第二级还没有处于'running'状态,那就意味着我们的 我们的第三级Node的onEnter函数没有被执行,那么在什么时候执行呢? void CCNode::onEnter() { //fix setTouchEnabled not take effect when called the function in onEnter in JSBinding. m_bRunning = true; if (m_eScriptType != kScriptTypeNone) { CCScriptEngineManager::sharedManager()->getScriptEngine()->executeNodeEvent(this, kCCNodeOnEnter); } //Judge the running state for prevent called onEnter method more than once,it's possible that this function called by addChild if (m_pChildren && m_pChildren->count() > 0) { CCObject* child; CCNode* node; CCARRAY_FOREACH(m_pChildren, child) { node = (CCNode*)child; if (!node->isRunning()) { node->onEnter(); //循环遍历子Node,执行所有子Node的onEnter方法,我们的UI树一定会 //加入到一个处于'running'状态的Node,因为我们必然会至少有一个处于'running' 状态的Node,即使是sceen,所以上面的第三级Node的OnEnter函数 //会在第二级Node加入到第一级Node是执行(假设第一级Node处于'running'状态)。 } } } this->resumeSchedulerAndActions(); }
相关文章推荐
- platform_device和platform_driver的注册过程,及probe函数何时调用的分析
- platform_device和platform_driver的注册过程,及probe函数何时调用的分析
- platform_device和platform_driver的注册过程,及probe函数何时调用的分析
- platform_device和platform_driver的注册过程,及probe函数何时调用的分析
- platform_device和platform_driver的注册过程,及probe函数何时调用的分析
- platform_device和platform_driver的注册过程,及probe函数何时调用的分析
- Linux内核分析-两种方式使用同一个系统调用
- 调用layoutSubviews各种情况分析
- Zygote调用流程分析
- C/C++函数调用过程分析
- Linux系统调用与ptrace分析
- Win32程序函数调用时堆栈变化情况分析
- BosonNLP情感分析API调用
- 从USB设备插上到驱动probe调用流程分析
- setTimeout()和setInterval() 何时被调用执行
- Servlet、Filter 和 Listener 调用顺序、生命周期的实验分析
- socket调用流程分析
- 窥探 kernel,just for fun --- 系统调用过程分析
- 理解APCS-- ARM过程调用标准(bootloader代码分析理论基础)
- RPC框架(八)dubbo源码分析--dubbo调用过程分析