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 18:55:45 |
👁️ 阅读: 8
根据浮生梦老师前端课程内容,我来帮你完善这个转盘脚本。你需要在每个ItemShow上循环挂载特效,并且实现"挂2移1、挂3移2...挂10移1"的链式效果。
```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 = {}
setData.index = 10174
setData.look = true
setData.bgVisible = false
setData.count = 1
setData.color = 225
local itemshow = {}
itemshow[1] = GUI:ItemShow_Create(disan, 'itemshow1', disanPos.width/2-194, disanPos.height/2+76, setData)
itemshow[2] = GUI:ItemShow_Create(disan, 'itemshow2', disanPos.width/2-84, disanPos.height/2+76, setData)
itemshow[3] = GUI:ItemShow_Create(disan, 'itemshow3', disanPos.width/2+26, disanPos.height/2+76, setData)
itemshow[4] = GUI:ItemShow_Create(disan, 'itemshow4', disanPos.width/2+136, disanPos.height/2+76, setData)
itemshow[5] = GUI:ItemShow_Create(disan, 'itemshow5', disanPos.width/2+136, disanPos.height/2-24, setData)
itemshow[6] = GUI:ItemShow_Create(disan, 'itemshow6', disanPos.width/2+136, disanPos.height/2-124, setData)
itemshow[7] = GUI:ItemShow_Create(disan, 'itemshow7', disanPos.width/2+26, disanPos.height/2-124, setData)
itemshow[8] = GUI:ItemShow_Create(disan, 'itemshow8', disanPos.width/2-84, disanPos.height/2-124, setData)
itemshow[9] = GUI:ItemShow_Create(disan, 'itemshow9', disanPos.width/2-194, disanPos.height/2-124, setData)
itemshow[10] = GUI:ItemShow_Create(disan, 'itemshow10', disanPos.width/2-194, disanPos.height/2-24, setData)
GUI:setAnchorPoint(disan, 0.5, 0.5)
GUI:setIgnoreContentAdaptWithSize(disan, false)
GUI:setChildrenCascadeOpacityEnabled(disan, true)
GUI:setOpacity(disan, 0) -- 初始完全透明
-- 特效挂载逻辑
local currentEffect = nil
local effectIndex = 1
local function createNextEffect()
-- 移除上一个特效
if currentEffect and not GUI:Win_IsNull(currentEffect) then
GUI:removeFromParent(currentEffect)
end
-- 如果已经到第10个,重新从第1个开始
if effectIndex > 10 then
effectIndex = 1
end
-- 创建新的特效
currentEffect = GUI:Effect_Create(itemshow[effectIndex], 'itemshow'..effectIndex, -20, 82, 0, 20212, 0, 0, 0, 1)
-- 设置特效播放完成事件,循环挂载
GUI:Effect_addOnCompleteEvent(currentEffect, function()
effectIndex = effectIndex + 1
createNextEffect()
end)
end
-- 2秒后淡入第三个序列帧,并在淡入完成后执行回调
SL:ScheduleOnce(function()
if not GUI:Win_IsNull(disan) then
-- 使用动作序列实现淡入效果
GUI:runAction(disan, GUI:ActionSequence(
GUI:ActionFadeIn(0.5),
GUI:CallFunc(function()
-- 淡入完成后添加按钮事件
GUI:addOnClickEvent(beimian, function()
GUI:removeFromParent(beimian)
end)
-- 开始特效循环
createNextEffect()
end)
))
end
end, 0.1)
end, 1)
end
SL:RegisterNetMsg(1030, zhuanpan)
```
**代码说明:**
1. **特效挂载逻辑**:
- 使用`currentEffect`变量记录当前特效
- 使用`effectIndex`记录当前挂载的ItemShow索引
- `createNextEffect()`函数实现"挂2移1、挂3移2..."的链式效果
2. **关键函数**:
- `GUI:Effect_Create()`:创建特效,参数依次为父节点、ID、x坐标、y坐标、z坐标、特效ID、旋转、缩放、透明度、是否循环
- `GUI:Effect_addOnCompleteEvent()`:特效播放完成事件,用于实现循环挂载
- `GUI:removeFromParent()`:移除上一个特效
3. **循环机制**:
- 特效播放完成后,`effectIndex`加1
- 当`effectIndex`超过10时,重置为1,实现无限循环
- 每次创建新特效前,先移除上一个特效
这样就能实现你想要的特效在10个ItemShow上循环挂载的效果了!
← 返回问答库