local parent = GUI:GetWindow(nil, "npc_" .. npcid)
if parent then
GUI:removeAllChildren(parent)
GUI:setPosition(parent, cogin.w / 2, cogin.h / 2)
else
parent = GUI:Win_Create("npc_" .. npcid, cogin.
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-06-29 17:23:36 |
👁️ 阅读: 6
根据浮生梦老师前端课程内容,你遇到的问题是因为点击事件传递到了快捷栏。需要设置`setSwallowTouches`为`true`来阻止事件穿透。
修改你的代码,在创建npc.bg时设置:
```lua
npc.bg = GUI:Image_Create(parent, "img_bj", 0.00, 0.00, "res/custom/qiangxing_ui/bg.png")
GUI:setAnchorPoint(npc.bg, 0.5, 0.5)
GUI:setTouchEnabled(npc.bg, true)
GUI:setSwallowTouches(npc.bg, true) -- 改为true,阻止事件向下传递
```
另外,背景图片bjt的点击事件会关闭整个窗口,如果你希望点击npc.bg区域不关闭窗口,需要确保bjt的`setSwallowTouches`也为`true`:
```lua
local bjt = GUI:Image_Create(parent, "bjt", 0, 0, "res/public/1900000651_1.png")
GUI:setAnchorPoint(bjt, 0.5, 0.5)
GUI:setContentSize(bjt, cogin.w + 100, cogin.h + 100)
GUI:setTouchEnabled(bjt, true)
GUI:setSwallowTouches(bjt, true) -- 添加这行
GUI:addOnClickEvent(bjt, function()
GUI:Win_Close(parent)
end)
```
这样设置后,点击npc.bg界面区域就不会穿透到快捷栏的道具上了。
← 返回问答库