local function zhuanpan(msgID, msgData)
local screenWidth = SL:GetMetaValue("SCREEN_WIDTH", 0)
local screenHeight = SL:GetMetaValue("SCREEN_HEIGHT", 0)
local parent = GUI:Win_Create("zhuanpan", 0, 0, 0, 0, false, false, true, false,
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-04-21 20:14:56 |
👁️ 阅读: 14
```lua
local function zhuanpan(msgID, msgData)
local screenWidth = SL:GetMetaValue("SCREEN_WIDTH", 0)
local screenHeight = SL:GetMetaValue("SCREEN_HEIGHT", 0)
local parent = GUI:Win_Create("zhuanpan", 0, 0, 0, 0, false, false, true, false, false, false, 1)
GUI:Win_SetMainHide(parent, true)
-- 第一个序列帧
local fullScreenAnim = GUI:Frames_Create(
parent,
"FullScreenFrames",
screenWidth/2,
screenHeight/2,
"res/yuding/donghua/a/a",
".png",
1,
15,
{speed = 100, count = 15, loop = 1}
)
GUI:setAnchorPoint(fullScreenAnim, 0.5, 0.5)
GUI:setContentSize(fullScreenAnim, screenWidth, screenHeight)
GUI:setIgnoreContentAdaptWithSize(fullScreenAnim, false)
-- 第一个序列帧播放完成后的处理
SL:ScheduleOnce(function()
if not GUI:Win_IsNull(fullScreenAnim) then
GUI:removeFromParent(fullScreenAnim)
end
-- 创建第二个序列帧
local secondAnim = GUI:Frames_Create(
parent,
"SecondFrames",
screenWidth/2,
screenHeight/2,
"res/yuding/donghua/b/b",
".png",
1,
15,
{speed = 100, count = 15, loop = -1}
)
GUI:setAnchorPoint(secondAnim, 0.5, 0.5)
GUI:setContentSize(secondAnim, screenWidth, screenHeight)
GUI:setIgnoreContentAdaptWithSize(secondAnim, false)
-- 创建第三个序列帧(初始透明)
local disan = GUI:Frames_Create(
parent,
"threeFrames",
screenWidth/2,
screenHeight/2,
"res/yuding/donghua/d/d",
".png",
1,
25,
{speed = 50, count = 25, loop = -1}
)
local disanPos = GUI:getContentSize(disan)
local beimian = GUI:Button_Create(disan, "bt1", disanPos.width/2-70, disanPos.height/2-300, "res/yuding/donghua/2.png")
local setData = {
[1] = {index = 10174, look = true, bgVisible = false, count = 1, color = 225},
[2] = {index = 10174, look = true, bgVisible = false, count = 1, color = 225},
[3] = {index = 10174, look = true, bgVisible = false, count = 1, color = 225},
[4] = {index = 10174, look = true, bgVisible = false, count = 1, color = 225},
[5] = {index = 10174, look = true, bgVisible = false, count = 1, color = 225},
[6] = {index = 10174, look = true, bgVisible = false, count = 1, color = 225},
[7] = {index = 10174, look = true, bgVisible = false, count = 1, color = 225},
[8] = {index = 10174, look = true, bgVisible = false, count = 1, color = 225},
[9] = {index = 10174, look = true, bgVisible = false, count = 1, color = 225},
[10] = {index = 10174, look = true, bgVisible = false, count = 1, color = 225},
}
local itemshow = {}
itemshow[1] = GUI:ItemShow_Create(disan, 'itemshow1', disanPos.width/2-194, disanPos.height/2+76, setData[1])
itemshow[2] = GUI:ItemShow_Create(disan, 'itemshow2', disanPos.width/2-84, disanPos.height/2+76, setData[2])
itemshow[3] = GUI:ItemShow_Create(disan, 'itemshow3', disanPos.width/2+26, disanPos.height/2+76, setData[3])
itemshow[4] = GUI:ItemShow_Create(disan, 'itemshow4', disanPos.width/2+136, disanPos.height/2+76, setData[4])
itemshow[5] = GUI:ItemShow_Create(disan, 'itemshow5', disanPos.width/2+136, disanPos.height/2-24, setData[5])
itemshow[6] = GUI:ItemShow_Create(disan, 'itemshow6', disanPos.width/2+136, disanPos.height/2-124, setData[6])
itemshow[7] = GUI:ItemShow_Create(disan, 'itemshow7', disanPos.width/2+26, disanPos.height/2-124, setData[7])
itemshow[8] = GUI:ItemShow_Create(disan, 'itemshow8', disanPos.width/2-84, disanPos.height/2-124, setData[8])
itemshow[9] = GUI:ItemShow_Create(disan, 'itemshow9', disanPos.width/2-194, disanPos.height/2-124, setData[9])
itemshow[10] = GUI:ItemShow_Create(disan, 'itemshow10', disanPos.width/2-194, disanPos.height/2-24, setData[10])
-- 为每个物品框添加特效
local effects = {}
for i = 1, 10 do
effects[i] = GUI:Effect_Create(itemshow[i], 'itemshow'..i, -20, 82, 0, 20212, 0, 0, 0, 1)
GUI:setVisible(effects[i], false) -- 初始隐藏特效
end
-- 当前选中的索引
local currentIndex = 1
local isAnimating = false
-- 按钮点击事件 - 实现残影效果的链式转盘
GUI:addOnClickEvent(beimian, function()
if isAnimating then return end -- 防止重复点击
isAnimating = true
-- 先移除按钮
GUI:removeFromParent(beimian)
-- 总动画步数改为4步
local totalSteps = 4
local currentStep = 1
-- 存储当前激活的特效索引
local activeEffects = {}
-- 计算延迟时间的函数 - 实现变速效果
local function getDelayTime(step)
local delayTime = 0.05
if step <= 1 then
-- 第1步较快
delayTime = 0.3
elseif step >= totalSteps - 1 then
-- 最后1步较慢
delayTime = 0.2
end
return delayTime
end
-- 在按钮点击事件中,修改残影效果函数
local function fadeOutOldEffects()
for idx, effectInfo in pairs(activeEffects) do
local effect = effectInfo.effect
local fadeTime = effectInfo.fadeTime
if fadeTime <= 0 then
-- 使用淡出动画而不是直接隐藏
GUI:runAction(effect, GUI:ActionSequence(
GUI:ActionFadeTo(0.1, 0),
GUI:ActionHide()
))
activeEffects[idx] = nil
else
effectInfo.fadeTime = fadeTime - 0.05
end
end
end
local function playChainAnimation(step)
if step > totalSteps then
-- 动画结束时,隐藏所有特效
for i = 1, 10 do
if i ~= currentIndex then -- 保留最后一个
GUI:setVisible(effects[i], false)
end
end
-- 确保最后一个特效显示
if effects[currentIndex] then
GUI:setVisible(effects[currentIndex], true)
-- 可以添加一个持续闪烁的效果
GUI:runAction(effects[currentIndex], GUI:ActionRepeatForever(
GUI:ActionSequence(
GUI:ActionFadeTo(0.5, 100),
GUI:ActionFadeTo(0.5, 255)
)
))
end
isAnimating = false
return
end
-- 更新当前索引(循环1-10)
currentIndex = ((step - 1) % 10) + 1
-- 显示当前特效并设置不透明度
if effects[currentIndex] then
GUI:setVisible(effects[currentIndex], true)
GUI:setOpacity(effects[currentIndex], 255)
end
-- 添加到活跃特效列表
activeEffects[currentIndex] = {
effect = effects[currentIndex],
fadeTime = 0.2
}
-- 处理残影效果
fadeOutOldEffects()
-- 计算延迟时间
local delayTime = getDelayTime(step)
-- 延迟后播放下一步
SL:ScheduleOnce(function()
playChainAnimation(step + 1)
end, delayTime)
end
-- 开始链式动画
playChainAnimation(1)
end)
GUI:setAnchorPoint(disan, 0.5, 0.5)
GUI:setIgnoreContentAdaptWithSize(disan, false)
GUI:setChildrenCascadeOpacityEnabled(disan, true)
GUI:setOpacity(disan, 0) -- 初始完全透明
-- 2秒后淡入第三个序列帧,并在淡入完成后执行回调
SL:ScheduleOnce(function()
if not GUI:Win_IsNull(disan) then
-- 使用动作序列实现淡入效果
GUI:runAction(disan, GUI:ActionSequence(
GUI:ActionFadeTo(0.5, 255),
GUI:CallFunc(function()
SL:Print("转盘界面已淡入完成")
end)
))
end
end, 0.1)
end, 1)
end
SL:RegisterNetMsg(1030, zhuanpan)
```
主要修改点:
1. **第78行**:将 `totalSteps = 40` 改为 `totalSteps = 4`,这样动画只执行4步
2. **第84-92行**:简化了 `getDelayTime` 函数,因为只有4步动画,所以调整了延迟时间逻辑
3. **第124行**:动画结束时,`currentIndex` 会停留在第4个位置(因为 `totalSteps = 4`)
这样修改后,点击按钮时特效只会依次在4个物品框上显示,而不是原来的40步长链式动画。动画会更简洁快速,符合你的要求。
注意:由于只有4步,所以最终会停留在第4个物品框上。如果你想让动画在4步后停在特定位置,可以调整 `currentIndex` 的计算逻辑。
← 返回问答库