博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CCNode 的onEnter函数何时调用分析
阅读量:4217 次
发布时间:2019-05-26

本文共 1912 字,大约阅读时间需要 6 分钟。

从源码中也看到,如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();   }

转载地址:http://jxsmi.baihongyu.com/

你可能感兴趣的文章
【一天一道LeetCode】#58. Length of Last Word
查看>>
【一天一道LeetCode】#59. Spiral Matrix II
查看>>
【一天一道LeetCode】#30. Substring with Concatenation of All Words
查看>>
【一天一道LeetCode】#60. Permutation Sequence.
查看>>
【一天一道LeetCode】#118. Pascal's Triangle
查看>>
JAVA实现文件树
查看>>
ebay api GetMyMessages 函数
查看>>
手动12 - 安装php加速器 Zend OPcache
查看>>
set theme -yii2
查看>>
yii2 - controller
查看>>
yii2 - 增加actions
查看>>
php图像处理函数大全(缩放、剪裁、缩放、翻转、旋转、透明、锐化的实例总结)
查看>>
magento url中 uenc 一坨编码 base64
查看>>
强大的jQuery焦点图无缝滚动走马灯特效插件cxScroll
查看>>
Yii2.0 数据库查询
查看>>
yii2 db 操作
查看>>
mongodb group 有条件的过滤组合个数。
查看>>
关于mongodb的 数组分组 array group
查看>>
MongoDB新的数据统计框架介绍
查看>>
mongodb 增加全文检索索引
查看>>