local zhuansheng = {}
function zhuansheng.main(param1, param2, param3, param4)
SL:print("===== 转生界面打开 =====")
lib:Require(param1, function(state)
if state then
if param1 then
zhuansheng.parent = lib:o
我理解你的需求了。你想要的是每次打开界面时,`Image_9`都显示在目标位置(77, 281),但是播放动画时要从起点位置开始移动。
问题出在你的代码逻辑上:在`update_effect_icons()`函数中,你直接设置了最终位置,这样动画就没有起点位置了。
解决方案是:**分开处理初始位置和动画起点位置**。以下是修改后的代码:
```lua
-- 显示特效图标
local function update_effect_icons()
local ui = zhuansheng.parent._ui
-- 获取当前转生等级
local curLevel = SL:GetMetaValue("RELEVEL") or 0
local cfg = zhuansheng.parent.cfg
if not cfg or not cfg[curLevel] then
return
end
local brightCount = 0
if cfg[curLevel].brightpicture then
brightCount = cfg[curLevel].brightpicture
else
-- 如果没有 brightpicture
brightCount = (curLevel - 1) % 5 + 1
end
-- 循环处理5个特效图标
for i = 1, 5 do
local objectName = "Effect_" .. i
if GUI:Win_IsNotNull(ui[objectName]) then
if i <= brightCount then
GUI:setVisible(ui[objectName], true)
else
GUI:setVisible(ui[objectName], false)
end
end
end
-- 先隐藏所有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控件
-- 关键修改:设置初始位置为目标位置
local targetX = 77 -- 最终X坐标
local targetY = 281 -- 最终Y坐标
if curLevel >= 1 then
if GUI:Win_IsNotNull(ui["Image_9"]) then
GUI:setVisible(ui["Image_9"], true)
-- 设置初始位置为目标位置(这样每次打开界面都显示在正确位置)
GUI:setPosition(ui["Image_9"], targetX, targetY)
end
end
if curLevel >= 2 then
if GUI:Win_IsNotNull(ui["Image_10"]) then
GUI:setVisible(ui["Image_10"], true)
end
end
if curLevel >= 3 then
if GUI:Win_IsNotNull(ui["Image_11"]) then
GUI:setVisible(ui["Image_11"], true)
end
end
if curLevel >= 4 then
if GUI:Win_IsNotNull(ui["Image_12"]) then
GUI:setVisible(ui["Image_12"], true)
end
end
if curLevel >= 5 then
if GUI:Win_IsNotNull(ui["Image_13"]) then
GUI:setVisible(ui["Image_13"], true)
end
end
end
-- 在升级按钮的点击事件中修改动画部分
if GUI:Win_IsNotNull(ui["Button_1"]) then
GUI:addOnClickEvent(ui["Button_1"], function()
SL:print("点击升级按钮")
-- 延迟按钮点击
GUI:delayTouchEnabled(ui["Button_1"], 0.2)
local msg = {}
msg.Script = zhuansheng.param1
local jsonstr = SL:JsonEncode(msg)
SL:SendLuaNetMsg(58003, zhuansheng.param2, 0, 0, jsonstr)
-- 检查条件
if next_data and lib and lib.checkitem then
local check_data = {
count = 2,
type1 = "物品",
name1 = next_data.name1 or "转生石",
value1 = tonumber(next_data.value1) or 0,
type2 = "货币",
name2 = next_data.name2 or "金币",
value2 = tonumber(next_data.value2) or 0,
}
local can_upgrade = lib:checkitem(check_data)
if not can_upgrade then
return
end
-- 动画执行前先设置起点位置(从左侧开始)
local startX = 0 -- 动画起点X坐标
local startY = targetY -- Y坐标保持与目标位置相同
-- 最终目标位置(保持不变)
local targetX = 77
local targetY = 281
-- 计算移动距离(从起点到目标位置)
local moveX = targetX - startX
local moveY = targetY - startY
-- 先将控件移动到起点位置
GUI:setPosition(ui.Image_9, startX, startY)
-- 动画回调函数
local callback = function()
-- 确保最终位置准确
GUI:setPosition(ui.Image_9, targetX, targetY)
SL:print("Image_9动画完成,已固定在最终位置")
end
-- 执行动画序列
GUI:runAction(ui.Image_9, GUI:ActionSequence(
GUI:ActionScaleTo(0.5, 1.4),
GUI:ActionScaleTo(0.5, 1),
GUI:ActionMoveBy(0.5, moveX, moveY), -- 从起点位置移动到目标位置
GUI:CallFunc(callback)
))
end
end)
end
```
**关键修改点:**
1. **初始位置**:在`update_effect_icons()`中,`Image_9`始终设置在目标位置(77, 281),这样每次打开界面都显示正确。
2. **动画起点**:在按钮点击事件中,动画开始前先将控件移动到起点位置(比如X=0,Y=281),然后执行从起点到目标的移动动画。
3. **逻辑分离**:初始显示和动画播放是两个独立的过程,互不干扰。
这样修改后,界面打开时`Image_9`显示在正确位置,点击升级按钮时,它会从起点位置动画移动到目标位置,实现了你想要的效果。
如果你想让动画起点在其他位置(比如屏幕左侧外),只需要调整`startX`和`startY`的值即可。