npc.Layout_2_img[index] = GUI:Image_Create(npc.buttron_Layout_2, "Layout_2_img" .. index, x, y, 'res/custom/qiangxing_ui/8.png')
GUI:setTouchEnabled(npc.Layout_2_img[index], true)
GUI:addOnClickEvent(npc.Layout_2_img[index], function(
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-06-29 13:53:12 |
👁️ 阅读: 1
这个问题的原因是点击事件被 `EquipShow` 控件阻挡了。根据浮生梦老师前端课程内容,`EquipShow` 控件默认是触摸启用的,会拦截其父控件上的点击事件。
解决方案是设置 `EquipShow` 控件为不可触摸,这样点击事件就能穿透到下面的图片控件:
```lua
npc.Layout_2_img[index] = GUI:Image_Create(npc.buttron_Layout_2, "Layout_2_img" .. index, x, y, 'res/custom/qiangxing_ui/8.png')
GUI:setTouchEnabled(npc.Layout_2_img[index], true)
GUI:addOnClickEvent(npc.Layout_2_img[index], function()
npc.load_Layout_2(index)
end)
npc.Layout_2_img_equip[index] = GUI:EquipShow_Create(npc.Layout_2_img[index], "Layout_2_img_equip" .. index, 0, 0, value.equipmentLocation, false, { look = true })
-- 关键代码:设置EquipShow控件为不可触摸
GUI:setTouchEnabled(npc.Layout_2_img_equip[index], false)
```
这样修改后,点击装备显示区域时,事件会穿透到下面的 `Image` 控件,从而触发 `load_Layout_2` 函数。
← 返回问答库