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 19:53:24 |
👁️ 阅读: 7
你的代码中拖影效果不明显,主要是因为缺少了关键的动作延迟和连续动画。要实现链式拖影效果,需要让每个物品框的动作有适当的时间间隔,而不是同时执行。
以下是修改后的代码,增加了动作延迟,创建了真正的链式拖影效果:
```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 function playChainAnimation(index)
if index > 10 then
-- 重置索引为1,实现循环
index = 1
SL:Print("索引已重置为1")
end
-- 显示当前特效
GUI:setVisible(effects[index], true)
-- 增强的拖影效果:先快速放大,然后缓慢缩小,增加延迟时间
GUI:runAction(itemshow[index], GUI:ActionSequence(
GUI:ActionScaleTo(0.1, 1.4), -- 快速放大到1.4倍
GUI:ActionScaleTo(0.2, 1.0), -- 缓慢缩小回原大小,制造拖影感
GUI:CallFunc(function()
-- 隐藏当前特效
GUI:setVisible(effects[index], false)
-- 计算下一个索引
local nextIndex = index + 1
if nextIndex > 10 then
nextIndex = 1
end
-- 更新当前索引
currentIndex = nextIndex
-- 增加延迟时间,让链式效果更明显
SL:ScheduleOnce(function()
-- 播放下一个
playChainAnimation(nextIndex)
end, 0.05) -- 50毫秒延迟,形成链式效果
end)
))
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. **增加延迟时间**:在`playChainAnimation`函数中,通过`SL:ScheduleOnce`增加了50毫秒的延迟,让每个物品框的动画有间隔
2. **调整动画参数**:放大到1.4倍,缩小时间增加到0.2秒,让拖影效果更明显
3. **链式触发**:每个物品框动画完成后,延迟50毫秒再播放下一个,形成真正的链式效果
这样修改后,转盘效果会像链条一样一个接一个地亮起,有明显的拖影和连续感。
← 返回问答库