关于cocostudio getChildByName递归获取child的错误bug

file:///Users/taoli/Desktop/屏幕快照%202015-11-26%20上午12.19.08.png
当cocostudio中出现层级嵌套的时候,getChildByName无法获取到第二层或层数更高的child,
所以改了CCNode.cpp的函数:

Node* Node::getChildByName(const std::string& name) const
{
CCASSERT(name.length() != 0, “Invalid name”);

std::hashstd::string h;
size_t hash = h(name);

for (const auto& child : _children)
{
    Node* c = child->getChildByNameRecursively(name, hash);
    if(c != nullptr)
    {
        return c;
    }

// Different strings may have the same hash code, but can use it to compare first for speed
}
return nullptr;
}

Node* Node::getChildByNameRecursively(const std::string& name, size_t hash)
{
printf("======= %s – %s", this->_name.c_str(), name.c_str());
if(this->_hashOfName == hash && this->_name.compare(name) == 0)
{
return this;
}
Vector<Node*> list = this->getChildren();
for (const auto& child : list)
{
Node* c = child->getChildByNameRecursively(name, hash);
if(c != nullptr)
{
return c;
}
}
return nullptr;

}