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
根据你的需求,我来帮你实现列表容器中图片的入场动画效果。你需要让ListView_1中的图片在界面打开时,按顺序从下方快速向上移动。
```lua
-- 在rongyuchenghao.upmain()函数中添加动画逻辑
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
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
-- 添加图片入场动画
local function playImageAnimation()
if GUI:Win_IsNull(list_layout) then
return
end
-- 获取列表容器中的所有图片项
local items = GUI:ListView_getItems(list_layout)
if not items or #items == 0 then
return
end
-- 设置初始位置(在屏幕下方)
for index, img in ipairs(items) do
if not GUI:Win_IsNull(img) then
-- 先设置到屏幕下方
local startY = -100 -- 从下方开始
GUI:setPositionY(img, startY)
-- 设置不透明度为0(完全透明)
GUI:setOpacity(img, 0)
-- 创建动画序列:延迟、上移、淡入
local delayTime = (index - 1) * 0.05 -- 每个图片间隔0.05秒
local moveAction = GUI:ActionMoveBy(0.3, 0, 100) -- 向上移动100像素
local fadeInAction = GUI:ActionFadeTo(0.3, 255) -- 淡入到完全不透明
-- 同时执行移动和淡入
local spawnAction = GUI:ActionSpawn(moveAction, fadeInAction)
-- 添加延迟后执行
local sequence = GUI:ActionSequence(GUI:DelayTime(delayTime), spawnAction)
-- 运行动画
GUI:runAction(img, sequence)
end
end
end
-- 延迟一小段时间后开始动画,确保界面已完全加载
SL:ScheduleOnce(function()
playImageAnimation()
end, 0.1)
-- 原有的其他逻辑保持不变
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. **动画原理**:
- 所有图片从屏幕下方(Y坐标为-100)开始
- 每个图片间隔0.05秒依次出现
- 同时执行向上移动和淡入效果
- 动画持续时间0.3秒,速度较快
2. **使用的函数**:
- `GUI:ListView_getItems(list_layout)` - 获取列表容器中的所有子项
- `GUI:setPositionY(img, startY)` - 设置图片的Y坐标
- `GUI:setOpacity(img, 0)` - 设置图片初始透明度为0(完全透明)
- `GUI:ActionMoveBy(time, x, y)` - 创建移动动作
- `GUI:ActionFadeTo(time, opacity)` - 创建淡入动作
- `GUI:ActionSpawn(action1, action2)` - 同时执行多个动作
- `GUI:DelayTime(time)` - 创建延迟动作
- `GUI:ActionSequence(action1, action2)` - 顺序执行动作
- `GUI:runAction(widget, action)` - 运行动作
- `SL:ScheduleOnce(callback, delay)` - 延迟执行函数
3. **动画效果**:
- 图片会依次从下方快速滑入
- 带有淡入效果,看起来更平滑
- 间隔时间短,整体动画速度快
如果你想要调整动画速度,可以修改以下参数:
- `0.05` - 图片之间的间隔时间(秒)
- `0.3` - 单个图片的动画持续时间(秒)
- `100` - 向上移动的距离(像素)
- `-100` - 起始Y坐标(负值表示在屏幕下方)
这样就能实现你想要的"依次按顺序往上面走"的动画效果了!