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
要实现列表容器中图片的向上移动动画,可以按照以下步骤修改代码:
```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
-- 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
-- 为列表容器中的图片添加向上移动动画
local function startImageAnimation()
-- 获取列表容器中的所有子节点
local items = GUI:ListView_getItems(list_layout)
if items and #items > 0 then
-- 设置所有图片初始位置在底部
for index, img in ipairs(items) do
if not GUI:Win_IsNull(img) then
-- 获取图片当前位置
local pos = GUI:getPosition(img)
-- 设置初始位置在容器底部下方
GUI:setPosition(img, pos.x, -100)
-- 创建向上移动的动作序列
-- 延迟时间根据索引递增,实现依次动画效果
local delayTime = (index - 1) * 0.05 -- 每个图片间隔0.05秒
local moveAction = GUI:ActionSequence(
GUI:DelayTime(delayTime),
GUI:ActionMoveTo(0.2, pos.x, pos.y) -- 0.2秒内移动到目标位置
)
-- 播放动画
GUI:runAction(img, moveAction)
end
end
end
end
-- 延迟一小段时间后开始动画,确保界面已完全加载
SL:ScheduleOnce(function()
startImageAnimation()
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. **快速向上移动**:每个图片在0.2秒内从底部移动到目标位置
2. **依次播放**:每个图片间隔0.05秒开始动画,形成依次上升的效果
3. **初始位置**:所有图片从容器底部下方开始
4. **异步执行**:使用SL:ScheduleOnce延迟0.1秒开始动画,确保界面完全加载
如果你想要更快的速度,可以调整`ActionMoveTo`的时间参数,比如改为`0.1`秒会更快。如果想要更紧凑的依次效果,可以减少`delayTime`的间隔值。