cocos2d学习(06)——CCNode::addChild(…)在做什么?

cocos2d学习(06)——CCNode::addChild(…)在做什么?,第1张

概述1: void CCNode::addChild(CCNode *child) 2: { 3: CCAssert( child != NULL, "Argument must be non-nil"); 4: this->addChild(child, child->m_nZOrder, child->m_nTag); 5: } 6:  7:  8: void CCN
 1: voID CCNode::addChild(CCNode *child)
 2: {
 3:     CCAssert( child != NulL,"Argument must be non-nil");
 4:     this->addChild(child,child->m_nZOrder,child->m_nTag);
 5: }
 6:
 7:
 8: voID CCNode::addChild(CCNode *child,int zOrder)
 9: {
 10:     CCAssert( child != NulL,monospace; wIDth: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 16pt; padding-right: 0px; background-color: white"> 11:     this->addChild(child,zOrder,monospace; wIDth: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 16pt; padding-right: 0px; background-color: #f4f4f4"> 12: }
 13:
 14:
 15: voID CCNode::addChild(CCNode *child,int zOrder,int tag)
 16: {
 17:     //判断参数是否合法
 18:     CCAssert( child != NulL,monospace; wIDth: 100%; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; border-left-style: none; line-height: 16pt; padding-right: 0px; background-color: white"> 19:     CCAssert( child->m_pParent == NulL,"child already added. It can't be added again");
 20:
 21: // 一个节点的父节点指针是CCNode*,其子节点保存在CCArray数组中,其本质也是CCObject
 22: // CCArray *m_pChildren; ///< array of children nodes
 23: // CCNode *m_pParent; ///< weak reference to parent node
 24:
 25:     if( ! m_pChildren )
 26:     {    //子节点数组不存在,申请空间
 27:         this->childrenAlloc();
 28: // voID CCNode::childrenAlloc(voID)
 29: // {
 30: // m_pChildren = CCArray::createWithCapacity(4); //create的时候调用了autorelease()
 31: // m_pChildren->retain(); //引用计数加一,防止被释放掉
 32: // }
 33:     }
 34:     //插入子节点指针
 35:     this->insertChild(child,zOrder);
 36:
 37: // int m_nTag; ///< a tag. Can be any number you assigned just to IDentify this node
 38: // 一个标记,可以是任意一个整数,你应该分配一个合理的值给这个节点
 39:     child->m_nTag = tag;    //设置Child的tag,可以是任意数
 40:
 41:     child->setParent(this);        //设置父节点为当前调用addChild函数的节点
 42:     child->setorderOfArrival(s_globalOrderOfArrivaL++);
 43:
 44:     if( m_bRunning )
 45:     {
 46:         child->onEnter();
 47:         child->onEnterTransitionDIDFinish();
 48:     }
 49: }
总结

以上是内存溢出为你收集整理的cocos2d学习(06)——CCNode::addChild(…)在做什么?全部内容,希望文章能够帮你解决cocos2d学习(06)——CCNode::addChild(…)在做什么?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1012992.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存