pointer23
null-defined
2014-09-16 06:06
采纳率: 100%
浏览 6.5k
已采纳

cocos2dx中关于addChild()引用计数具体位置

都说cocos2d中使用addChild()时引用计数加一,请问具体在哪儿?`void Node::addChild(Node *child, int zOrder, int tag)
{

CCASSERT( child != nullptr, "Argument must be non-nil");
CCASSERT( child->_parent == nullptr, "child already added. It can't be added again");

if (_children.empty())
{
    this->childrenAlloc();
}

this->insertChild(child, zOrder);

#if CC_USE_PHYSICS
if (child->getPhysicsBody() != nullptr)
{
child->getPhysicsBody()->setPosition(this->convertToWorldSpace(child->getPosition()));
}

for (Node* node = this->getParent(); node != nullptr; node = node->getParent())
{
    if (dynamic_cast<Scene*>(node) != nullptr)
    {
        (dynamic_cast<Scene*>(node))->addChildToPhysicsWorld(child);
        break;
    }
}

#endif

child->_tag = tag;

child->setParent(this);
child->setOrderOfArrival(s_globalOrderOfArrival++);

if( _running )
{
    child->onEnter();
    // prevent onEnterTransitionDidFinish to be called twice when a node is added in onEnter
    if (_isTransitionFinished) {
        child->onEnterTransitionDidFinish();
    }
}

if (_cascadeColorEnabled)
{
    updateCascadeColor();
}

if (_cascadeOpacityEnabled)
{
    updateCascadeOpacity();
}

}
`

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • pointer23
    null-defined 2014-09-23 15:52
    已采纳

    进入this->insertChild(child, zOrder);
    再进入
    _children.pushBack(child);
    就可以看到了
    void pushBack(T object)
    {
    CCASSERT(object != nullptr, "The object should not be nullptr");
    _data.push_back( object );
    //addChild的引用计数加一在这
    object->retain();
    }``

    点赞 评论

相关推荐