function qiehuan(actor)
local k = SL:GetMetaValue("SCREEN_WIDTH")
local g = SL:GetMetaValue("SCREEN_HEIGHT")
-- 创建父节点
local parent = GUI:Win_Create("MapChangeContainer", 0, 0, 0, 0, false, false, true, false, false, false, 1)
--
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-04-15 13:40:42 |
👁️ 阅读: 12
根据浮生梦老师前端课程内容,我来帮你完善这个切换动画效果。你需要使用动作序列来实现这个动画效果。
```lua
function qiehuan(actor)
local k = SL:GetMetaValue("SCREEN_WIDTH")
local g = SL:GetMetaValue("SCREEN_HEIGHT")
-- 创建父节点
local parent = GUI:Win_Create("MapChangeContainer", 0, 0, 0, 0, false, false, true, false, false, false, 1)
-- 容器宽200,高63
local containerWidth = 200
local containerHeight = 63
-- 计算容器位置(正上方居中)
local posX = k / 2 - containerWidth / 3
local posY = g - 163
-- 创建容器
local container = GUI:Layout_Create(parent, "top_container", posX, posY, containerWidth, containerHeight, false)
-- 设置容器锚点为中心点
GUI:setAnchorPoint(container, 0.5, 0.5)
-- 给容器添加背景
local bg = GUI:Image_Create(container, "bg_image", 0, 0, "res/xixi/ditu/3.png")
GUI:setContentSize(bg, containerWidth, containerHeight)
-- 设置背景锚点也为中心点
GUI:setAnchorPoint(bg, 0.5, 0.5)
-- 先设置初始状态:宽度为0,缩放为0.1,透明度为0
GUI:setContentSize(container, 0, containerHeight)
GUI:setOpacity(bg, 0)
-- 创建动画序列
local function hideContainer()
-- 1秒后淡出隐藏
GUI:runAction(container, GUI:ActionSequence(
GUI:DelayTime(1),
GUI:ActionFadeOut(1),
GUI:CallFunc(function()
GUI:setVisible(container, false)
GUI:removeFromParent(container)
end)
))
end
-- 执行主动画序列
GUI:runAction(container, GUI:ActionSequence(
-- 第一步:1秒内拉伸至原宽度,放大到原尺寸,淡入到透明255
GUI:ActionSpawn(
GUI:ActionScaleTo(1, 100), -- 缩放回100%
GUI:ActionMoveTo(1, posX, posY) -- 移动到原位置
),
GUI:CallFunc(function()
-- 设置最终尺寸
GUI:setContentSize(container, containerWidth, containerHeight)
-- 设置最终透明度
GUI:setOpacity(bg, 255)
end),
-- 最后1秒淡出后隐藏
GUI:DelayTime(1),
GUI:ActionFadeOut(1),
GUI:CallFunc(function()
GUI:setVisible(container, false)
GUI:removeFromParent(container)
end)
))
end
```
**注意:**
1. 由于浮生梦老师前端课程内容中没有找到直接修改宽度的动作函数,我使用了`ActionScaleTo`来模拟缩放效果
2. `ActionSpawn`可以让多个动作同时执行
3. 动画结束后会自动隐藏并移除容器
4. 设置锚点为(0.5, 0.5)确保以中心点为原点进行缩放
如果你需要更精确的宽度变化动画,可能需要使用其他方法来实现。有什么不明白的地方可以继续问我!
根据浮生梦老师前端课程内容,我来帮你完善这个切换动画效果。你需要使用动作序列来实现这个动画效果。
```lua
function qiehuan(actor)
local k = SL:GetMetaValue("SCREEN_WIDTH")
local g = SL:GetMetaValue("SCREEN_HEIGHT")
-- 创建父节点
local parent = GUI:Win_Create("MapChangeContainer", 0, 0, 0, 0, false, false, true, false, false, false, 1)
-- 容器宽200,高63
local containerWidth = 200
local containerHeight = 63
-- 计算容器位置(正上方居中)
local posX = k / 2 - containerWidth / 3
local posY = g - 163
-- 创建容器
local container = GUI:Layout_Create(parent, "top_container", posX, posY, containerWidth, containerHeight, false)
-- 设置容器锚点为中心点
GUI:setAnchorPoint(container, 0.5, 0.5)
-- 给容器添加背景
local bg = GUI:Image_Create(container, "bg_image", 0, 0, "res/xixi/ditu/3.png")
GUI:setContentSize(bg, containerWidth, containerHeight)
-- 设置背景锚点也为中心点
GUI:setAnchorPoint(bg, 0.5, 0.5)
-- 先设置初始状态:宽度为0,缩放为0.1,透明度为0
GUI:setContentSize(container, 0, containerHeight)
GUI:setOpacity(bg, 0)
-- 创建动画序列
local function hideContainer()
-- 1秒后淡出隐藏
GUI:runAction(container, GUI:ActionSequence(
GUI:DelayTime(1),
GUI:ActionFadeOut(1),
GUI:CallFunc(function()
GUI:setVisible(container, false)
GUI:removeFromParent(container)
end)
))
end
-- 执行主动画序列
GUI:runAction(container, GUI:ActionSequence(
-- 第一步:1秒内拉伸至原宽度,放大到原尺寸,淡入到透明255
GUI:ActionSpawn(
GUI:ActionScaleTo(1, 100), -- 缩放回100%
GUI:ActionMoveTo(1, posX, posY) -- 移动到原位置
),
GUI:CallFunc(function()
-- 设置最终尺寸
GUI:setContentSize(container, containerWidth, containerHeight)
-- 设置最终透明度
GUI:setOpacity(bg, 255)
end),
-- 最后1秒淡出后隐藏
GUI:DelayTime(1),
GUI:ActionFadeOut(1),
GUI:CallFunc(function()
GUI:setVisible(container, false)
GUI:removeFromParent(container)
end)
))
end
```
**注意:**
1. 由于浮生梦老师前端课程内容中没有找到直接修改宽度的动作函数,我使用了`ActionScaleTo`来模拟缩放效果
2. `ActionSpawn`可以让多个动作同时执行
3. 动画结束后会自动隐藏并移除容器
4. 设置锚点为(0.5, 0.5)确保以中心点为原点进行缩放
如果你需要更精确的宽度变化动画,可能需要使用其他方法来实现。有什么不明白的地方可以继续问我!
← 返回问答库