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, fal
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-04-20 14:59:56 |
👁️ 阅读: 9
你的代码思路不错,但需要调整一下。根据你的需求“中间留一张卡牌不动”,我们可以设定一个固定的卡牌索引(比如第5张)不执行移动动画。
下面是修改后的代码,主要改动是添加了条件判断,让指定的卡牌保持原位:
```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
-- 保持原位,不执行任何动画
SL:print("第5张卡牌保持不动")
else
-- 其他卡牌执行移动动画
GUI:runAction(beimian, GUI:ActionSequence(
GUI:ActionMoveTo(1, -72, -103),
GUI:DelayTime(0.5),
GUI:CallFunc(function()
local targetY = -103
if i % 2 == 1 then
targetY = -103 + 172
else
targetY = -103 - 172
end
GUI:runAction(beimian, GUI:ActionSequence(
GUI:ActionMoveTo(0.5, -72, targetY),
GUI:DelayTime(0.3),
GUI:ActionMoveTo(0.5, -72, -103),
GUI:DelayTime(0.5),
GUI:CallFunc(function()
local targetX = -72
if i % 3 == 1 then
targetX = -72 - 142
else
targetX = -72 + 142
end
GUI:runAction(beimian, GUI:ActionSequence(
GUI:ActionMoveTo(0.5, targetX, -103),
GUI:DelayTime(0.3),
GUI:ActionMoveTo(0.5, -72, -103)
))
end)
))
end)
))
end
end
end)
end
```
**主要改动说明:**
1. 添加了 `if i == 5 then` 条件判断,让第5张卡牌不执行移动动画
2. 不动的卡牌会打印提示信息并保持原位
3. 其他卡牌(1-4和6-10)正常执行原来的三阶段动画
**建议:**
- 你可以通过修改 `i == 5` 中的数字来指定哪张卡牌不动
- 如果想多张卡牌不动,可以使用 `if i == 5 or i == 8 then` 这样的条件
- 注意锚点设置,确保卡牌初始位置正确
这样修改后,点击按钮时第5张卡牌会保持在原来的位置,其他卡牌会执行移动到中心然后上下、左右分开的动画效果。
← 返回问答库