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 16:02:36 |
👁️ 阅读: 9
```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 beimian = GUI:Button_Create(disan, "bt1",screenWidth/2-80, screenHeight/2-270, "res/yuding/donghua/2.png")
GUI:setAnchorPoint(disan, 0.5, 0.5)
GUI:setContentSize(disan, screenWidth, screenHeight)
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(2),
GUI:CallFunc(function()
-- 淡入完成后添加按钮事件(如果之前没添加的话)
GUI:addOnClickEvent(beimian, function()
-- 点击按钮后播放第四个序列帧
local fourthAnim = GUI:Frames_Create(
parent,
"FourthFrames",
screenWidth/2,
screenHeight/2,
"res/yuding/donghua/c/c",
".png",
1,
41,
{speed = 80, count = 41, loop = 1}
)
GUI:setAnchorPoint(fourthAnim, 0.5, 0.5)
GUI:setContentSize(fourthAnim, screenWidth, screenHeight)
GUI:setIgnoreContentAdaptWithSize(fourthAnim, false)
end)
end)
))
end
end, 0.1)
end, 1)
end
SL:RegisterNetMsg(1030, zhuanpan)
```
**代码说明:**
1. **序列帧创建**:使用`GUI:Frames_Create()`函数创建序列帧动画,参数包括父节点、唯一ID、位置、资源前缀/后缀、起始/结束帧、播放参数表
2. **定时器使用**:使用`SL:ScheduleOnce()`进行单次延迟执行,符合浮生梦老师前端课程规范
3. **空值判断**:使用`GUI:Win_IsNull()`检查控件是否为空,避免空指针错误
4. **淡入效果**:使用`GUI:ActionFadeIn(2)`实现2秒淡入效果,配合`GUI:ActionSequence()`动作序列
5. **按钮事件**:在淡入完成后添加按钮点击事件,点击时创建第四个序列帧
6. **坐标计算**:`screenWidth/2, screenHeight/2`确保序列帧居中显示
**参数说明:**
- `prefix`:资源前缀路径,如"res/yuding/donghua/c/c"
- `suffix`:资源后缀,如".png"
- `ext`:播放参数表,包含speed(播放速度)、count(图片数量)、loop(循环次数,-1为无限循环)
注意:确保资源路径正确,序列帧图片命名符合规范(如c_1.png, c_2.png等)。
← 返回问答库