今天逛cocos论坛的时候 发现有这样一个接口
findChildren
还有一个findChild没有在3.10或者自己的项目中找到使用 应该是与getChildByName用法一样
findChildren查了半天用途
他可以获得所有同一名称的子节点
看示例
--复制24个节点 设置得到的坐标 并添加到容器层里面 这个容器层作为可克隆的节点
function PXUISkill:initPageItem()
local function addItemToPanel(i)
local item = self.m_Image_DownItem:clone()
--item:show()
item:setTag(i)
local tbPoint = self.tbPanelSPos[i]
item:setPosition(tbPoint.x, tbPoint.y)
self.m_Panel_SkillPvItem:addChild(item)
end
for i = 1, Msd.DOWN_SKI_NUM do
addItemToPanel(i)
end
--得到全部的克隆节点
local findChildren = cc.utils:findChildren(self.m_Panel_SkillPvItem, "m_Image_DownItem")
dump(findChildren, "findChildren = ")
local a = self.m_Panel_SkillPvItem:getChildByName("m_Image_DownItem")
dump(a, "a = ")
end
输出
[LUA-print] dump from: [string ".\app/game_ui/PXUISkill/PXUISkill.lua"]:262: in
function 'initPageItem'
[LUA-print] - "findChildren = " = {
[LUA-print] - 1 = userdata: 0x0acdfec0
[LUA-print] - 2 = userdata: 0x07c4b788
[LUA-print] - 3 = userdata: 0x075b1500
[LUA-print] - 4 = userdata: 0x0e13cc60
[LUA-print] - 5 = userdata: 0x0a7c30c0
[LUA-print] - 6 = userdata: 0x07626a68
[LUA-print] - 7 = userdata: 0x0e134740
[LUA-print] - 8 = userdata: 0x0759aff0
[LUA-print] - 9 = userdata: 0x0e7322d8
[LUA-print] - 10 = userdata: 0x0a7b7858
[LUA-print] - 11 = userdata: 0x0a7b7878
[LUA-print] - 12 = userdata: 0x07f70768
[LUA-print] - 13 = userdata: 0x07f70788
[LUA-print] - 14 = userdata: 0x0e59fd78
[LUA-print] - 15 = userdata: 0x0e59fd98
[LUA-print] - 16 = userdata: 0x0e107180
[LUA-print] - 17 = userdata: 0x0e1071a0
[LUA-print] - 18 = userdata: 0x0e587ce8
[LUA-print] - 19 = userdata: 0x0e587d08
[LUA-print] - 20 = userdata: 0x0acd6c30
[LUA-print] - 21 = userdata: 0x0acd6c50
[LUA-print] - 22 = userdata: 0x0acdeb58
[LUA-print] - 23 = userdata: 0x0acdeb78
[LUA-print] - 24 = userdata: 0x0af04018
[LUA-print] - }
[LUA-print] dump from: [string ".\app/game_ui/PXUISkill/PXUISkill.lua"]:264: in
function 'initPageItem'
[LUA-print] - "a = " = userdata: 0x0acdfec0
可见
cc.utils:findChildren可获得全部子节点
也可以#结果 得到有多少个这个名字的节点