cocos2d学习(06)——CCNode::addChild(…)在做什么?
发布时间:2020-12-14 19:28:40 所属栏目:百科 来源:网络整理
导读: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(
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: }
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |