resetAllButtons()
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-06-14 12:28:01 |
👁️ 阅读: 2
```lua
function resetAllButtons()
-- 获取所有需要重置的按钮
local buttons = {
"btn_top_1", "btn_top_2", "btn_top_3", "btn_top_4", "btn_top_5"
}
-- 遍历所有按钮
for i, btnName in ipairs(buttons) do
local widget = GUI:getChildByName(parentNode, btnName)
-- 检查控件是否存在且不为空
if widget and not GUI:Win_IsNull(widget) then
-- 停止所有动作
GUI:stopAllActions(widget)
-- 设置可见性为false
GUI:setVisible(widget, false)
-- 重置位置到原点
GUI:setPosition(widget, 0, 0)
-- 重置透明度
GUI:setOpacity(widget, 255)
-- 重置旋转
GUI:setRotation(widget, 0)
-- 重置缩放
GUI:setScale(widget, 1, 1)
end
end
SL:print("所有按钮已重置完成")
end
```
这个函数会:
1. 停止按钮上的所有动画动作
2. 隐藏所有按钮
3. 重置按钮位置到(0,0)
4. 恢复按钮的透明度、旋转和缩放
使用前需要先定义`parentNode`为按钮所在的父节点,比如:
```lua
local parentNode = GUI:Win_Create("MainUI", 0, 0, 0, 0, false, false, true, false, false, false, 1)
```
函数中使用的所有GUI函数都来自浮生梦老师前端课程内容,确保兼容性。
← 返回问答库