local heinu = {}
function heinu.main(param1, param2, param3, param4)
lib:Require(param1, function(state)
if state then
if param1 then
heinu.parent = lib:openwin(param1, nil, true, param4) or {}
根据浮生梦老师前端课程内容,我来帮你添加动画效果。这里使用动作序列来实现你的需求:
```lua
local heinu = {}
function heinu.main(param1, param2, param3, param4)
lib:Require(param1, function(state)
if state then
if param1 then
heinu.parent = lib:openwin(param1, nil, true, param4) or {}
heinu.param1 = param1
end
if param2 then
heinu.param2 = param2
end
if param3 then
heinu.param3 = param3
end
if heinu.parent.cfg and next(heinu.parent.cfg) then
heinu.upmain()
else
lib:msg("系统未配置!")
GUI:Win_Close(heinu.parent._parent)
end
end
end)
end
function heinu.upmain()
if not heinu.parent or not heinu.parent._ui then
return
end
local ui = heinu.parent._ui
local var = tonumber(lib:getstr("U47") or 0)
SL:Print("获取当前焚天等级 var =", var)
if not GUI:Win_IsNull(ui.Text_1) then
GUI:Text_setString(ui.Text_1, (var or 0))
end
-- 先隐藏所有Image_9到Image_15和Image_2到Image_8
for i = 2, 15 do
local imgName = "Image_" .. i
if ui[imgName] and not GUI:Win_IsNull(ui[imgName]) then
GUI:setVisible(ui[imgName], false)
end
end
-- 根据var等级显示并执行动画
local function playAnimation(imgTitle, imgCoal, delayTime)
if not GUI:Win_IsNull(ui[imgTitle]) and not GUI:Win_IsNull(ui[imgCoal]) then
-- 设置初始状态
GUI:setVisible(ui[imgTitle], true)
GUI:setVisible(ui[imgCoal], true)
GUI:setOpacity(ui[imgTitle], 0)
GUI:setOpacity(ui[imgCoal], 255)
-- 感谢标题淡入动画
local fadeInAction = GUI:ActionFadeTo(0.5, 255)
GUI:runAction(ui[imgTitle], fadeInAction)
-- 黑煤球1秒后向下移动并淡出
SL:ScheduleOnce(function()
local moveDown = GUI:ActionMoveBy(0.5, 0, -100)
local fadeOut = GUI:ActionFadeTo(0.5, 0)
local sequence = GUI:ActionSequence(moveDown, fadeOut)
GUI:runAction(ui[imgCoal], sequence)
end, 1.0 + delayTime)
end
end
-- 根据var等级执行动画
if var >= 1 then
playAnimation("Image_9", "Image_2", 0)
end
if var >= 2 then
playAnimation("Image_10", "Image_3", 0.1)
end
if var >= 3 then
playAnimation("Image_11", "Image_4", 0.2)
end
if var >= 4 then
playAnimation("Image_12", "Image_5", 0.3)
end
if var >= 5 then
playAnimation("Image_13", "Image_6", 0.4)
end
if var >= 6 then
playAnimation("Image_14", "Image_7", 0.5)
end
if var >= 7 then
playAnimation("Image_15", "Image_8", 0.6)
end
if GUI:Win_IsNotNull(ui.Button_1) then
GUI:addOnClickEvent(ui.Button_1, function()
SL:print("点击了第1个按钮")
GUI:delayTouchEnabled(ui.Button_1, 0.2)
local msg = {}
msg.Script = heinu.param1
local jsonstr = SL:JsonEncode(msg)
SL:SendLuaNetMsg(58003, heinu.param2, 0, 0, jsonstr)
end)
end
end
-- 注册游戏事件
SL:RegisterLUAEvent(LUA_EVENT_PLAYER_EQUIP_CHANGE, "heinu", function(data)
if data and data.opera == 1 then
heinu.upmain()
end
end)
SL:RegisterLUAEvent(LUA_EVENT_SERVER_VALUE_CHANGE, "heinu", function(data)
if next(data) and data.key == "U47" then
heinu.upmain() -- 注意这里应该是heinu.upmain(),不是fentian.upmain()
end
end)
SL:RegisterLUAEvent(LUA_EVENT_CLOSEWIN, "heinu", function(CLOSEWINdata)
if CLOSEWINdata and CLOSEWINdata == "heinu" then
SL:UnRegisterLUAEvent(LUA_EVENT_PLAYER_EQUIP_CHANGE, "heinu")
SL:UnRegisterLUAEvent(LUA_EVENT_SERVER_VALUE_CHANGE, "heinu")
SL:UnRegisterLUAEvent(LUA_EVENT_CLOSEWIN, "heinu")
end
end)
return heinu
```
主要修改说明:
1. **动画逻辑**:
- `Image_9`到`Image_15`(感谢标题)会从透明淡入显示
- 1秒后,对应的`Image_2`到`Image_8`(黑煤球)会向下移动100像素并淡出消失
2. **动画效果**:
- 淡入效果:`GUI:ActionFadeTo(0.5, 255)`
- 移动效果:`GUI:ActionMoveBy(0.5, 0, -100)` 向下移动
- 淡出效果:`GUI:ActionFadeTo(0.5, 0)`
- 动作序列:`GUI:ActionSequence()` 组合多个动作
3. **时间控制**:
- 使用`SL:ScheduleOnce()`实现1秒延迟
- 不同等级之间有0.1秒的延迟间隔,避免同时播放太拥挤
4. **修复的bug**:
- 第45行的事件回调中,将`fentian.upmain()`改为`heinu.upmain()`
这样就能实现你想要的动画效果了,每个等级的动画会依次播放,视觉效果更佳!