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
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-04-21 18:43:07 |
👁️ 阅读: 3
根据浮生梦老师前端课程内容,我来帮你修改代码实现转盘特效滚动效果。
主要修改点:
1. 添加按钮点击事件来触发特效
2. 使用Effect_Create创建转盘特效
3. 调整特效位置到转盘中心
修改后的代码:
```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")
-- 添加按钮点击事件触发转盘特效
GUI:addOnClickEvent(beimian, function()
-- 创建转盘滚动特效
-- 参数说明:parent, id, x, y, zOrder, sfxId, offX, offY, isFront, loop
local eff = GUI:Effect_Create(disan, "zhuanpan_effect",
disanPos.width/2, -- 居中X坐标
disanPos.height/2, -- 居中Y坐标
0, -- Z轴顺序
20212, -- 特效ID
0, -- X偏移
0, -- Y偏移
1, -- 是否在前面显示
1 -- 循环播放
)
-- 设置特效锚点居中
GUI:setAnchorPoint(eff, 0.5, 0.5)
-- 特效播放完成回调
GUI:Effect_addOnCompleteEvent(eff, function()
SL:Print("转盘特效播放完成")
-- 特效播放完成后可以移除
if not GUI:Win_IsNull(eff) then
GUI:removeFromParent(eff)
end
end)
end)
local setData = {}
setData.index = 10174
setData.look = true
setData.bgVisible = false
setData.count = 1
setData.color = 225
local itemshow1 = GUI:ItemShow_Create(disan, 'itemshow1', disanPos.width/2-194, disanPos.height/2+76, setData)
local itemshow2 = GUI:ItemShow_Create(disan, 'itemshow2', disanPos.width/2-84, disanPos.height/2+76, setData)
local itemshow3 = GUI:ItemShow_Create(disan, 'itemshow3', disanPos.width/2+26, disanPos.height/2+76, setData)
local itemshow4 = GUI:ItemShow_Create(disan, 'itemshow4', disanPos.width/2+136, disanPos.height/2+76, setData)
local itemshow5 = GUI:ItemShow_Create(disan, 'itemshow5', disanPos.width/2+136, disanPos.height/2-24, setData)
local itemshow6 = GUI:ItemShow_Create(disan, 'itemshow6', disanPos.width/2+136, disanPos.height/2-124, setData)
local itemshow7 = GUI:ItemShow_Create(disan, 'itemshow7', disanPos.width/2+26, disanPos.height/2-124, setData)
local itemshow8 = GUI:ItemShow_Create(disan, 'itemshow8', disanPos.width/2-84, disanPos.height/2-124, setData)
local itemshow9 = GUI:ItemShow_Create(disan, 'itemshow9', disanPos.width/2-194, disanPos.height/2-124, setData)
local itemshow10 = 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) -- 初始完全透明
-- 2秒后淡入第三个序列帧,并在淡入完成后执行回调
SL:ScheduleOnce(function()
if not GUI:Win_IsNull(disan) then
-- 使用动作序列实现淡入效果
GUI:runAction(disan, GUI:ActionSequence(
GUI:ActionFadeIn(0.5),
GUI:CallFunc(function()
-- 淡入完成后打印提示
SL:Print("转盘界面已淡入显示")
end)
))
end
end, 0.1)
end, 1)
end
SL:RegisterNetMsg(1030, zhuanpan)
```
**修改说明:**
1. **按钮事件**:在`beimian`按钮的点击事件中添加了特效创建逻辑
2. **特效位置**:将特效放置在转盘中心位置(`disanPos.width/2`, `disanPos.height/2`)
3. **特效参数**:
- `parent`: `disan` - 将特效添加到转盘容器中
- `id`: `"zhuanpan_effect"` - 特效唯一标识
- `sfxId`: `20212` - 特效ID(根据你的需求调整)
- `isFront`: `1` - 特效显示在前面
- `loop`: `1` - 循环播放
4. **特效回调**:使用`GUI:Effect_addOnCompleteEvent`监听特效播放完成事件
**注意:**
- 特效ID `20212` 需要确认是否是你想要的特效
- 如果需要不同的播放方式(如单次播放),可以调整`loop`参数
- 特效位置可以根据实际效果微调`offX`和`offY`参数
这样修改后,点击按钮就会在转盘中心位置播放滚动特效了!
← 返回问答库