-- client.lua
local luosha_client = {}
function luosha_client.main(param1, param2, param3, param4)
lib:Require(param1, function(state)
if state then
if param1 then
luosha_client.parent = lib:openwin(param1, ni
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-03-26 18:19:28 |
👁️ 阅读: 3
根据浮生梦老师前端课程内容,要实现点击按钮2后隐藏按钮2并显示Button_3,可以在按钮2的点击事件中添加相应的逻辑。以下是修改后的代码示例:
```lua
if GUI:Win_IsNotNull(ui.Button_2) then
GUI:addOnClickEvent(ui.Button_2, function()
SL:Print("点击了第2个按钮")
GUI:delayTouchEnabled(ui.Button_2, 0.2)
-- 隐藏Button_2
GUI:setVisible(ui.Button_2, false)
GUI:setTouchEnabled(ui.Button_2, false)
-- 显示Button_3
if GUI:Win_IsNotNull(ui.Button_3) then
GUI:setVisible(ui.Button_3, true)
GUI:setTouchEnabled(ui.Button_3, true)
end
local msg = {}
msg.Script = luosha_client.param1
local jsonstr = SL:JsonEncode(msg)
SL:SendLuaNetMsg(58003, luosha_client.param2, 1, 0, jsonstr)
end)
end
```
关键点说明:
1. 使用 `GUI:setVisible(widget, false)` 隐藏按钮2
2. 使用 `GUI:setTouchEnabled(widget, false)` 禁用按钮2的触摸事件,防止误操作
3. 使用 `GUI:setVisible(widget, true)` 显示按钮3
4. 使用 `GUI:setTouchEnabled(widget, true)` 启用按钮3的触摸事件
这样修改后,当玩家点击按钮2时,按钮2会立即隐藏,同时按钮3会显示出来。
根据浮生梦老师前端课程内容,要实现点击按钮2后隐藏按钮2并显示Button_3,可以在按钮2的点击事件中添加相应的逻辑。以下是修改后的代码示例:
```lua
if GUI:Win_IsNotNull(ui.Button_2) then
GUI:addOnClickEvent(ui.Button_2, function()
SL:Print("点击了第2个按钮")
GUI:delayTouchEnabled(ui.Button_2, 0.2)
-- 隐藏Button_2
GUI:setVisible(ui.Button_2, false)
GUI:setTouchEnabled(ui.Button_2, false)
-- 显示Button_3
if GUI:Win_IsNotNull(ui.Button_3) then
GUI:setVisible(ui.Button_3, true)
GUI:setTouchEnabled(ui.Button_3, true)
end
local msg = {}
msg.Script = luosha_client.param1
local jsonstr = SL:JsonEncode(msg)
SL:SendLuaNetMsg(58003, luosha_client.param2, 1, 0, jsonstr)
end)
end
```
关键点说明:
1. 使用 `GUI:setVisible(widget, false)` 隐藏按钮2
2. 使用 `GUI:setTouchEnabled(widget, false)` 禁用按钮2的触摸事件,防止误操作
3. 使用 `GUI:setVisible(widget, true)` 显示按钮3
4. 使用 `GUI:setTouchEnabled(widget, true)` 启用按钮3的触摸事件
这样修改后,当玩家点击按钮2时,按钮2会立即隐藏,同时按钮3会显示出来。
← 返回问答库