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-20 15:07:53 |
👁️ 阅读: 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)
local fullScreenAnim = GUI:Frames_Create(
parent,
"FullScreenFrames",
screenWidth/2,
screenHeight/2,
"res/public/word_fubentg_",
".png",
1,
10,
{speed = 100, count = 10, loop = -1}
)
GUI:setAnchorPoint(fullScreenAnim, 0.5, 0.5)
GUI:setContentSize(fullScreenAnim, screenWidth, screenHeight)
GUI:setIgnoreContentAdaptWithSize(fullScreenAnim, false)
local layout = GUI:Layout_Create(parent, "layout", screenWidth/2, screenHeight/2, 900, 500)
if layout then
GUI:setAnchorPoint(layout, 0, 0)
GUI:setTouchEnabled(layout, true)
end
local bg_kuang = GUI:Image_Create(layout, "bg_kuang", 450, 250, "res/01/010011.jpg")
if bg_kuang then
GUI:setAnchorPoint(bg_kuang, 0.5, 0.5)
GUI:setContentSize(bg_kuang, {width = 900, height = 500})
end
GUI:LoadExport(layout, "zhuanpan")
local ui = GUI:ui_delegate(layout)
GUI:setCascadeOpacityEnabled(layout, true)
GUI:setOpacity(layout, 0)
GUI:runAction(layout, GUI:ActionFadeIn(2))
GUI:addOnClickEvent(ui.Button_1, function()
GUI:removeFromParent(ui.Button_1)
local cardPositions = {}
local cardSizes = {}
for i = 1, 10 do
local pos = GUI:getPosition(ui['Image_'..i])
local size = GUI:getContentSize(ui['Image_'..i])
cardPositions[i] = {x = pos.x, y = pos.y}
cardSizes[i] = {width = size.width, height = size.height}
GUI:removeFromParent(ui['Image_'..i])
local beimian = GUI:Button_Create(layout, "bei"..i, cardPositions[i].x, cardPositions[i].y, "res/public_win32/1900000610.png")
GUI:setContentSize(beimian, cardSizes[i].width, cardSizes[i].height)
GUI:setVisible(beimian, true)
-- 第5张卡牌不动
if i ~= 5 then
-- 其他卡牌执行移动动画
local sequenceActions = {}
-- 第一阶段:移动到中心位置
table.insert(sequenceActions, GUI:ActionMoveTo(1, -72, -103))
table.insert(sequenceActions, GUI:DelayTime(0.5))
-- 第二阶段:上下移动
table.insert(sequenceActions, GUI:CallFunc(function()
local targetY = -103
if i % 2 == 1 then
targetY = -103 + 172
else
targetY = -103 - 172
end
local subActions = {}
table.insert(subActions, GUI:ActionMoveTo(0.5, -72, targetY))
table.insert(subActions, GUI:DelayTime(0.3))
table.insert(subActions, GUI:ActionMoveTo(0.5, -72, -103))
table.insert(subActions, GUI:DelayTime(0.5))
-- 第三阶段:左右移动
table.insert(subActions, GUI:CallFunc(function()
local targetX = -72
if i % 3 == 1 then
targetX = -72 - 142
else
targetX = -72 + 142
end
local finalActions = {}
table.insert(finalActions, GUI:ActionMoveTo(0.5, targetX, -103))
table.insert(finalActions, GUI:DelayTime(0.3))
table.insert(finalActions, GUI:ActionMoveTo(0.5, -72, -103))
-- 第四阶段:旋转一周并回到原位
table.insert(finalActions, GUI:DelayTime(0.5))
table.insert(finalActions, GUI:CallFunc(function()
-- 计算延迟时间,让卡牌依次返回
local delayTime = (i-1) * 0.5
SL:ScheduleOnce(function()
-- 旋转一周动画
GUI:runAction(beimian, GUI:ActionSequence(
GUI:ActionRotateBy(1, 360),
GUI:ActionMoveTo(0.5, cardPositions[i].x, cardPositions[i].y)
))
end, delayTime)
end))
GUI:runAction(beimian, GUI:ActionSequence(unpack(finalActions)))
end))
GUI:runAction(beimian, GUI:ActionSequence(unpack(subActions)))
end))
GUI:runAction(beimian, GUI:ActionSequence(unpack(sequenceActions)))
end
end
end)
end
```
**代码说明:**
1. **动作序列构建**:使用`GUI:ActionSequence()`将多个动作组合成顺序播放的动画序列
2. **延迟执行**:使用`GUI:DelayTime()`在动作之间添加延迟
3. **回调函数**:使用`GUI:CallFunc()`在特定时间点执行Lua函数
4. **移动动画**:使用`GUI:ActionMoveTo(time, x, y)`实现位置移动
5. **旋转动画**:使用`GUI:ActionRotateBy(time, angle)`实现360度旋转
6. **定时器使用**:使用`SL:ScheduleOnce(callback, delay)`实现卡牌依次返回的延迟效果
7. **位置记录**:使用`GUI:getPosition()`获取原始位置,最后用`GUI:ActionMoveTo()`返回
**注意:**
- 第5张卡牌保持不动(`if i ~= 5 then`条件判断)
- 其他卡牌先聚集到中心,然后上下移动,再左右移动
- 最后依次延迟0.5秒旋转一周并返回原始位置
- 所有动画时间参数可以根据实际效果调整
这样实现后,点击按钮会触发卡牌动画,最后所有卡牌(除第5张)都会旋转一周并回到最初分散的位置。
← 返回问答库