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:00:06 |
👁️ 阅读: 6
我来帮你修改代码,实现残影效果和变速动画。根据浮生梦老师前端课程内容,我来调整你的链式转盘动画:
```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)
-- 总动画步数
local totalSteps = 40 -- 假设定格为40步
local currentStep = 1
-- 存储当前激活的特效索引
local activeEffects = {}
-- 计算延迟时间的函数 - 实现变速效果
local function getDelayTime(step)
local delayTime = 0.05
if step <= 3 then
-- 前3步变快
delayTime = 0.4 - 0.1 * step
elseif step >= totalSteps - 3 then
-- 后3步变慢
delayTime = 0.1 + 0.1 * (step + 3 - totalSteps)
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:setVisible(effect, false)
activeEffects[idx] = nil
else
-- 更新淡出时间
effectInfo.fadeTime = fadeTime - 0.05
end
end
end
-- 链式转盘动画
local function playChainAnimation(step)
if step > totalSteps then
isAnimating = false
return
end
-- 计算当前应该显示哪个特效(循环1-10)
local effectIndex = ((step - 1) % 10) + 1
-- 显示当前特效
GUI:setVisible(effects[effectIndex], true)
-- 添加到活跃特效列表,设置淡出时间为0.2秒
activeEffects[effectIndex] = {
effect = effects[effectIndex],
fadeTime = 0.2 -- 0.2秒后淡出
}
-- 添加缩放动画效果
GUI:runAction(itemshow[effectIndex], GUI:ActionSequence(
GUI:ActionScaleTo(0.1, 1.2),
GUI:ActionScaleTo(0.1, 1.0)
))
-- 处理残影效果
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. **变速动画效果**:使用`getDelayTime`函数实现前快后慢的变速效果
- 前3步逐渐变快(0.4秒→0.1秒)
- 中间步保持0.05秒
- 后3步逐渐变慢(0.1秒→0.4秒)
2. **残影效果**:使用`activeEffects`表记录当前活跃的特效
- 每个特效显示后记录到活跃列表
- 每次动画步进时更新淡出时间
- 淡出时间到0时隐藏特效
3. **总步数控制**:设置`totalSteps = 40`步
- 特效在1-10之间循环显示
- 实现完整的变速动画流程
这样修改后,转盘动画会有明显的残影效果,并且速度会从快到慢变化,最后定格在某个位置上。
← 返回问答库