diff --git a/cocos2dx/base_nodes/CCNode.cpp b/cocos2dx/base_nodes/CCNode.cpp index b7eb000b7a..08e8a4ff11 100644 --- a/cocos2dx/base_nodes/CCNode.cpp +++ b/cocos2dx/base_nodes/CCNode.cpp @@ -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 diff --git a/cocos2dx/base_nodes/CCNode.h b/cocos2dx/base_nodes/CCNode.h index ccd6fa0824..eae2f45883 100644 --- a/cocos2dx/base_nodes/CCNode.h +++ b/cocos2dx/base_nodes/CCNode.h @@ -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