-- 先隐藏所有Image控件
for i = 9, 13 do
local objectName = "Image_" .. i
if GUI:Win_IsNotNull(ui[objectName]) then
GUI:setVisible(ui[objectName], false)
end
end
-- 根据转生等级显示对应的Image控件
if curLevel >= 1
要实现延迟1秒显示效果,你可以使用浮生梦老师前端课程中提到的 `GUI:Timeline_DelayTime` 函数配合 `GUI:Timeline_Show` 函数。
这里有两种实现方案:
**方案一:使用Timeline系列函数(推荐)**
```lua
-- 先隐藏所有Image控件
for i = 9, 13 do
local objectName = "Image_" .. i
if GUI:Win_IsNotNull(ui[objectName]) then
GUI:setVisible(ui[objectName], false)
end
end
-- 延迟1秒后根据转生等级显示对应的Image控件
if curLevel >= 1 and GUI:Win_IsNotNull(ui["Image_9"]) then
GUI:Timeline_Show(ui["Image_9"], 1) -- 延迟1秒显示
end
if curLevel >= 2 and GUI:Win_IsNotNull(ui["Image_10"]) then
GUI:Timeline_Show(ui["Image_10"], 1)
end
if curLevel >= 3 and GUI:Win_IsNotNull(ui["Image_11"]) then
GUI:Timeline_Show(ui["Image_11"], 1)
end
if curLevel >= 4 and GUI:Win_IsNotNull(ui["Image_12"]) then
GUI:Timeline_Show(ui["Image_12"], 1)
end
if curLevel >= 5 and GUI:Win_IsNotNull(ui["Image_13"]) then
GUI:Timeline_Show(ui["Image_13"], 1)
end
```
**方案二:使用动作序列(如果需要更复杂的动画)**
```lua
-- 先隐藏所有Image控件
for i = 9, 13 do
local objectName = "Image_" .. i
if GUI:Win_IsNotNull(ui[objectName]) then
GUI:setVisible(ui[objectName], false)
end
end
-- 使用动作序列实现延迟显示
local function showImageWithDelay(widget)
if GUI:Win_IsNotNull(widget) then
GUI:runAction(widget, GUI:ActionSequence(
GUI:DelayTime(1), -- 延迟1秒
GUI:CallFunc(function()
GUI:setVisible(widget, true)
end)
))
end
end
-- 根据转生等级调用
if curLevel >= 1 then
showImageWithDelay(ui["Image_9"])
end
if curLevel >= 2 then
showImageWithDelay(ui["Image_10"])
end
if curLevel >= 3 then
showImageWithDelay(ui["Image_11"])
end
if curLevel >= 4 then
showImageWithDelay(ui["Image_12"])
end
if curLevel >= 5 then
showImageWithDelay(ui["Image_13"])
end
```
**函数说明:**
- `GUI:Timeline_Show(widget, time)`:延迟指定时间后显示控件
- `GUI:DelayTime(time)`:创建延迟动作,单位秒
- `GUI:ActionSequence(...)`:将多个动作组合成顺序播放的序列
- `GUI:CallFunc(callback)`:创建回调函数动作
建议使用方案一,代码更简洁且专门用于延迟显示。如果之后需要添加淡入效果,可以结合 `GUI:ActionFadeIn` 动作。