GUI:addOnClickEvent(npc.ui.jobBut_1, function()
if a == 1 then
a = 2
GUI:Timeline_MoveTo(npc.ui.Panel_1, {x = 5, y = 316}, 0, function() end)
GUI:Timeline_MoveTo(npc.ui.Panel_3, {x = 5, y = -316}, 0, func
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-04-27 20:46:01 |
👁️ 阅读: 7
要实现点击后0.5秒内禁止再次点击的效果,可以在动画开始时禁用按钮,然后通过定时器在0.5秒后重新启用按钮。以下是修改后的代码:
```lua
GUI:addOnClickEvent(npc.ui.jobBut_1, function()
-- 先禁用按钮,防止重复点击
GUI:setEnabled(npc.ui.jobBut_1, false)
if a == 1 then
a = 2
GUI:Timeline_MoveTo(npc.ui.Panel_1, {x = 5, y = 316}, 0, function() end)
GUI:Timeline_MoveTo(npc.ui.Panel_3, {x = 5, y = -316}, 0, function() end)
elseif a == 2 then
a = 3
GUI:Timeline_MoveTo(npc.ui.Panel_2, {x = 5, y = 316}, 0, function() end)
GUI:Timeline_MoveTo(npc.ui.Panel_1, {x = 5, y = -316}, 0, function() end)
else
a = 1
GUI:Timeline_MoveTo(npc.ui.Panel_3, {x = 5, y = 316}, 0, function() end)
GUI:Timeline_MoveTo(npc.ui.Panel_2, {x = 5, y = -316}, 0, function() end)
end
local panelName = "Panel_" .. a -- 子控件基础容器
local moveActionUp_1 = GUI:ActionMoveTo(0.3, 0, 35) -- 上移动画效果
local moveActionDown_1 = GUI:ActionMoveTo(0.2, 0, 0) -- 上移动画效果
local moveAction_Up = GUI:ActionSequence(moveActionUp_1, moveActionDown_1) -- 合并动画
-- GUI:Timeline_MoveTo(npc.ui[panelName], {x = 5, y = 0}, 0.35, function() end) -- 基础容器上滑动画
GUI:runAction(npc.ui[panelName], moveAction_Up)
local delayAction = GUI:DelayTime(0.25)
local easeAction = GUI:ActionEaseExponentialOut(moveAction_Up) -- 缓冲效果
local sequenceAction = GUI:ActionSequence(delayAction, easeAction) -- 延迟播放
GUI:runAction(npc.ui[panelName], sequenceAction)
-- 使用单次定时器,0.5秒后重新启用按钮
SL:ScheduleOnce(function()
GUI:setEnabled(npc.ui.jobBut_1, true)
end, 0.5)
end)
```
**关键点说明:**
1. `GUI:setEnabled(npc.ui.jobBut_1, false)` - 点击时立即禁用按钮
2. `SL:ScheduleOnce(function() ... end, 0.5)` - 0.5秒后执行回调函数重新启用按钮
3. 这样就能确保点击后按钮有0.5秒的冷却时间,防止动画播放期间重复点击
如果动画播放时间可能超过0.5秒,你可以根据实际情况调整延迟时间,或者将按钮启用放在动画结束的回调中。
要实现点击后0.5秒内禁止再次点击的效果,可以在动画开始时禁用按钮,然后通过定时器在0.5秒后重新启用按钮。以下是修改后的代码:
```lua
GUI:addOnClickEvent(npc.ui.jobBut_1, function()
-- 先禁用按钮,防止重复点击
GUI:setEnabled(npc.ui.jobBut_1, false)
if a == 1 then
a = 2
GUI:Timeline_MoveTo(npc.ui.Panel_1, {x = 5, y = 316}, 0, function() end)
GUI:Timeline_MoveTo(npc.ui.Panel_3, {x = 5, y = -316}, 0, function() end)
elseif a == 2 then
a = 3
GUI:Timeline_MoveTo(npc.ui.Panel_2, {x = 5, y = 316}, 0, function() end)
GUI:Timeline_MoveTo(npc.ui.Panel_1, {x = 5, y = -316}, 0, function() end)
else
a = 1
GUI:Timeline_MoveTo(npc.ui.Panel_3, {x = 5, y = 316}, 0, function() end)
GUI:Timeline_MoveTo(npc.ui.Panel_2, {x = 5, y = -316}, 0, function() end)
end
local panelName = "Panel_" .. a -- 子控件基础容器
local moveActionUp_1 = GUI:ActionMoveTo(0.3, 0, 35) -- 上移动画效果
local moveActionDown_1 = GUI:ActionMoveTo(0.2, 0, 0) -- 上移动画效果
local moveAction_Up = GUI:ActionSequence(moveActionUp_1, moveActionDown_1) -- 合并动画
-- GUI:Timeline_MoveTo(npc.ui[panelName], {x = 5, y = 0}, 0.35, function() end) -- 基础容器上滑动画
GUI:runAction(npc.ui[panelName], moveAction_Up)
local delayAction = GUI:DelayTime(0.25)
local easeAction = GUI:ActionEaseExponentialOut(moveAction_Up) -- 缓冲效果
local sequenceAction = GUI:ActionSequence(delayAction, easeAction) -- 延迟播放
GUI:runAction(npc.ui[panelName], sequenceAction)
-- 使用单次定时器,0.5秒后重新启用按钮
SL:ScheduleOnce(function()
GUI:setEnabled(npc.ui.jobBut_1, true)
end, 0.5)
end)
```
**关键点说明:**
1. `GUI:setEnabled(npc.ui.jobBut_1, false)` - 点击时立即禁用按钮
2. `SL:ScheduleOnce(function() ... end, 0.5)` - 0.5秒后执行回调函数重新启用按钮
3. 这样就能确保点击后按钮有0.5秒的冷却时间,防止动画播放期间重复点击
如果动画播放时间可能超过0.5秒,你可以根据实际情况调整延迟时间,或者将按钮启用放在动画结束的回调中。
← 返回问答库