首先声明本人是cocos2的新手 有写的不对的地方 还希望各位提出来 不要让我误人子弟 文章只做抛砖引玉
深度优先用递归实现:
--遍历搜索节点根据name值(深度优先)
function cc.exports.SeekNodeByName_(parent, name)
if parent and parent:getName() == name then return parent end
local findNode = nil
local children = parent:getChildren()
if children then
for k,v in pairs(children) do
if v then
findNode = SeekNodeByName_(v, name)
if findNode then
return findNode
end
end
end
end
return nil
end
同理可得 SeekNodeByTag_