issue #1549: Added some functions for CCNode.

virtual void removeFromParent();
virtual void removeChild(CCNode* child);
virtual void removeChildByTag(int tag);
virtual void removeAllChildren();
This commit is contained in:
James Chen 2012-11-05 18:41:52 +08:00
parent 2b734c6e04
commit 270676b74d
2 changed files with 43 additions and 2 deletions

View File

@ -537,6 +537,11 @@ void CCNode::addChild(CCNode *child)
this->addChild(child, child->m_nZOrder, child->m_nTag);
}
void CCNode::removeFromParent()
{
this->removeFromParentAndCleanup(true);
}
void CCNode::removeFromParentAndCleanup(bool cleanup)
{
if (m_pParent != NULL)
@ -545,6 +550,11 @@ void CCNode::removeFromParentAndCleanup(bool cleanup)
}
}
void CCNode::removeChild(CCNode* child)
{
this->removeChild(child, true);
}
/* "remove" logic MUST only be on this method
* If a class want's to extend the 'removeChild' behavior it only needs
* to override this method
@ -563,6 +573,11 @@ void CCNode::removeChild(CCNode* child, bool cleanup)
}
}
void CCNode::removeChildByTag(int tag)
{
this->removeChildByTag(tag, true);
}
void CCNode::removeChildByTag(int tag, bool cleanup)
{
CCAssert( tag != kCCNodeTagInvalid, "Invalid tag");
@ -579,6 +594,11 @@ void CCNode::removeChildByTag(int tag, bool cleanup)
}
}
void CCNode::removeAllChildren()
{
this->removeAllChildrenWithCleanup(true);
}
void CCNode::removeAllChildrenWithCleanup(bool cleanup)
{
// not using detachChild improves speed here

View File

@ -380,21 +380,42 @@ public:
// composition: REMOVE
/** Remove itself from its parent node forcing a cleanup.
If the node orphan, then nothing happens.
@since v2.1
*/
virtual void removeFromParent();
/** Remove itself from its parent node. If cleanup is true, then also remove all actions and callbacks.
If the node orphan, then nothing happens.
@since v0.99.3
*/
void removeFromParentAndCleanup(bool cleanup);
virtual void removeFromParentAndCleanup(bool cleanup);
/** Removes a child from the container forcing a cleanup
@since v2.1
*/
virtual void removeChild(CCNode* child);
/** Removes a child from the container. It will also cleanup all running actions depending on the cleanup parameter.
@since v0.7.1
*/
virtual void removeChild(CCNode* child, bool cleanup);
/** Removes a child from the container by tag value forcing a cleanup.
@since v2.1
*/
virtual void removeChildByTag(int tag);
/** Removes a child from the container by tag value. It will also cleanup all running actions depending on the cleanup parameter
@since v0.7.1
*/
void removeChildByTag(int tag, bool cleanup);
virtual void removeChildByTag(int tag, bool cleanup);
/** Removes all children from the container forcing a cleanup.
@since v2.1
*/
virtual void removeAllChildren();
/** Removes all children from the container and do a cleanup all running actions depending on the cleanup parameter.
@since v0.7.1