local rongyuchenghao = {}
function rongyuchenghao.main(param1, param2, param3, param4)
lib:Require(param1, function(state)
if state then
if param1 then
rongyuchenghao.parent = lib:openwin(param1, nil, true, pa
根据浮生梦老师前端课程内容,要实现你需要的动画效果,可以在界面打开时创建一系列动作序列。你需要为每个图片创建从相同位置(Image_8的位置)向上移动的动画,并设置延迟时间来实现依次播放。
以下是修改后的代码示例,主要修改 `rongyuchenghao.upmain()` 函数中的相关部分:
```lua
function rongyuchenghao.upmain()
if not rongyuchenghao.parent or not rongyuchenghao.parent._ui then
return
end
local var = tonumber(lib:getstr("U12") or 0) or 0
local ui = rongyuchenghao.parent._ui
local level = var
local next_level = var + 1
local cur_data = rongyuchenghao.parent.cfg[level] or {}
local next_data = rongyuchenghao.parent.cfg[next_level] or {}
local cur_cfg = rongyuchenghao.parent.cfg[1]
local next_cfg = rongyuchenghao.parent.cfg[next_level]
if not next_cfg then
return
end
local list_layout = ui.ListView_1
if not GUI:Win_IsNull(list_layout) then
-- 8级:把 1-8 移到末尾
if var >= 8 then
for i = 1, 8 do
local img = ui["Image_"..i]
if img and not GUI:Win_IsNull(img) then
local current_parent = GUI:getParent(img)
if current_parent ~= list_layout then
GUI:removeFromParent(img)
GUI:ListView_pushBackCustomItem(list_layout, img)
end
end
end
end
if var >= 16 then
for i = 9, 16 do
local img = ui["Image_"..i]
if img and not GUI:Win_IsNull(img) then
local current_parent = GUI:getParent(img)
if current_parent ~= list_layout then
GUI:removeFromParent(img)
GUI:ListView_pushBackCustomItem(list_layout, img)
end
end
end
end
end
-- 获取Image_8的位置作为动画起始点
local startPos = nil
local img8 = ui["Image_8"]
if img8 and not GUI:Win_IsNull(img8) then
startPos = GUI:getPosition(img8)
end
-- 为前7个图片创建动画
for i = 1, 7 do
local imgName = "Image_" .. i
local imgWidget = ui[imgName]
if imgWidget and not GUI:Win_IsNull(imgWidget) and startPos then
-- 先设置到Image_8的位置
GUI:setPosition(imgWidget, startPos.x, startPos.y)
GUI:setVisible(imgWidget, true)
-- 创建动画序列:延迟 + 向上移动
local delayTime = (i - 1) * 0.05 -- 每个间隔0.05秒,速度很快
local moveAction = GUI:ActionMoveBy(0.2, 0, -50) -- 快速向上移动50像素
local sequence = GUI:ActionSequence(
GUI:DelayTime(delayTime),
moveAction
)
GUI:runAction(imgWidget, sequence)
end
end
for i = 23, 44 do
local imgName = "Image_" .. i
local imgWidget = ui[imgName]
if imgWidget then
local targetLevel = i - 22
if var >= targetLevel then
GUI:setVisible(imgWidget, true)
else
GUI:setVisible(imgWidget, false)
end
end
end
for i = 1, 22 do
local textName = "Text_" .. i
local textWidget = ui[textName]
if textWidget then
if var >= i then
GUI:setVisible(textWidget, true)
GUI:Text_setTextColor(textWidget, "#FFFFFF")
else
GUI:setVisible(textWidget, true)
GUI:Text_setTextColor(textWidget, "#808080")
end
end
end
create_attr(cur_data, next_data)
lib:createitemlist(ui.item_layout, next_cfg, 10)
if lib:checkitem(next_cfg, true) then
rongyuchenghao.btn_green_frames = lib:create_green_point(ui["Button_1"], 108, 6)
else
lib:remove_widget(rongyuchenghao.btn_green_frames)
end
GUI:addOnClickEvent(ui["Button_1"], function()
GUI:delayTouchEnabled(ui["Button_1"], 0.2)
local msg = {}
msg.Script = rongyuchenghao.param1
local jsonstr = SL:JsonEncode(msg)
SL:SendLuaNetMsg(58003, rongyuchenghao.param2, 0, 0, jsonstr)
end)
end
```
关键修改说明:
1. **获取起始位置**:先获取 `Image_8` 的坐标位置作为动画起点
2. **设置初始位置**:将前7个图片先设置到与 `Image_8` 相同的位置
3. **创建动画序列**:
- 使用 `GUI:DelayTime()` 实现依次播放效果
- 使用 `GUI:ActionMoveBy()` 创建向上移动动画
- 使用 `GUI:ActionSequence()` 组合延迟和移动动作
4. **参数调整**:
- `delayTime = (i - 1) * 0.05`:每个图片间隔0.05秒,速度很快
- `GUI:ActionMoveBy(0.2, 0, -50)`:0.2秒内向上移动50像素
这样当界面打开时,前7个图片会从 `Image_8` 的位置依次快速向上移动,形成你想要的动画效果。