在运用移除的接口中,有几个接口,有时自己就会混乱,不知道该用哪一个,还有就是运用每一个的结果是怎么样的,接下来我看CCNode下的移除接口源码进行了了解
1)removeFromParent
2)removeFromParentAndCleanup
3)removeChild
4)removeByTag
5)removeChildByName
6)removeAllChildren
这六个都是CCNode中的函数,其实这前面五个的用途跟效果是一样的
第一个到第四个最后都会调用第五个函数来实现移除Child
再移除过程中,会遍历曾经addChild过的每一个Child,获得一个Child列表中你要移除的Child的Index索引值
然后根据这个索引值来移除相应的Child
void Node::removeChild(Node* child, bool cleanup /* = true */)
{
// explicit nil handling
if (_children.empty())
{
return;
}
ssize_t index = _children.getIndex(child);
if( index != CC_INVALID_INDEX )
this->detachChild( child, index, cleanup );
}
其中的removeAllChildren