Exemplo n.º 1
0
//----------------------------------------------------------------------------
MovablePtr Node::SetChild (int i, Movable* child)
{
    if (child)
    {
        assertion(!child->GetParent(), "The child already has a parent.\n");
    }

    const int numChildren = (int)mChild.size();
    if (0 <= i && i < numChildren)
    {
		// 将旧的孩子移除
        MovablePtr previousChild = mChild[i];
        if (previousChild)
        {
            previousChild->SetParent(0);
        }

		// 插入新的孩子到空位
        if (child)
        {
            child->SetParent(this);
        }

        mChild[i] = child;
        return previousChild;
    }

	// 孩子超出范围,将其插入到孩子队列末尾
    if (child)
    {
        child->SetParent(this);
    }
    mChild.push_back(child);
    return 0;
}
Exemplo n.º 2
0
//----------------------------------------------------------------------------
void Node::DetachAllChildren ()
{
	for (int i=0; i<(int)mChild.size(); i++)
	{
		 MovablePtr child = mChild[i];

		 if (child)
		 {
			 child->SetParent(0);
			 mChild[i] = 0;
		 }
	}
}
Exemplo n.º 3
0
//----------------------------------------------------------------------------
MovablePtr Node::DetachChildAt (int i)
{
    if (0 <= i && i < (int)mChild.size())
    {
        MovablePtr child = mChild[i];
        if (child)
        {
            child->SetParent(0);
            mChild[i] = 0;
        }
        return child;
    }
    return 0;
}
Exemplo n.º 4
0
//----------------------------------------------------------------------------
void Node::DetachAllChildren ()
{
	for (int i=0; i<(int)mChild.size(); i++)
	{
		 MovablePtr child = mChild[i];

		 if (child)
		 {
			 child->SetParent(0);
			 OnChildRemoved(child);
			 mChild[i] = 0;
		 }
	}

	mIsNeedCalUpdateChild = true;
}
Exemplo n.º 5
0
//----------------------------------------------------------------------------
MovablePtr Node::DetachChildAt (int i)
{
    if (0 <= i && i < (int)mChild.size())
    {
        MovablePtr child = mChild[i];
        if (child)
        {
            child->SetParent(0);
			OnChildRemoved(child);
            mChild[i] = 0;

			mIsNeedCalUpdateChild = true;
        }
        return child;
    }
    return 0;
}
Exemplo n.º 6
0
//----------------------------------------------------------------------------
bool Node::DetachChildByName (const std::string &name)
{
	for (int i=0; i<(int)mChild.size(); i++)
	{
		MovablePtr child = mChild[i];

		if (child != 0 && child->GetName() == name)
		{
			child->SetParent(0);
			OnChildRemoved(child);
			mChild[i] = 0;

			mIsNeedCalUpdateChild = true;

			return true;
		}

	}

	return false;
}