function zhuansheng.tigger_tips()
local ui = zhuansheng.parent._ui
local parent = ui.ImageView
local curLevel = lib:get_zs_level() or 0
local old_layout = GUI:getChildByName(parent, "zs_tips_layout")
SL:Print("GUI:Win_IsNull(old
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-04-23 16:17:45 |
👁️ 阅读: 9
你的代码中,`lib:widget_popUp_move_to_fadeout(tips_layout)` 这行调用的自定义函数可能没有正确设置延时动作。根据浮生梦老师前端课程内容,动画延时需要使用 `GUI:DelayTime(time)` 来创建延时动作,并组合到动作序列中。
以下是修改后的 `zhuansheng.tigger_tips` 函数,确保动画有延时效果:
```lua
function zhuansheng.tigger_tips()
local ui = zhuansheng.parent._ui
local parent = ui.ImageView
local curLevel = lib:get_zs_level() or 0
local old_layout = GUI:getChildByName(parent, "zs_tips_layout")
SL:Print("GUI:Win_IsNull(old_layout)=", GUI:Win_IsNull(old_layout))
if GUI:Win_IsNotNull(old_layout) then
local text = GUI:getChildByName(old_layout, "zs_Text_1")
SL:Print("GUI:Win_IsNull(text)=", GUI:Win_IsNull(text))
if text then
GUI:Text_setString(text, curLevel)
end
SL:Print("111111111111")
return
end
-- Create tips_layout
local tips_layout = GUI:Layout_Create(parent, "zs_tips_layout", 0, 0, 246, 368, false)
GUI:setAnchorPoint(tips_layout, 0.00, 0.00)
GUI:setTouchEnabled(tips_layout, false)
GUI:setTag(tips_layout, 0)
-- Create tips_eff
local tips_eff = GUI:Effect_Create(tips_layout, "zs_tips_eff", 252, 202, 0, 86416, 0, 0, 0, 1)
GUI:setTag(tips_eff, 0)
-- Create tips_img
local tips_img = GUI:Image_Create(tips_layout, "zs_tips_img", 0, 0, "res/yidalu/zhuansheng4.0/zhuansheng tup.png")
GUI:setAnchorPoint(tips_img, 0.00, 0.00)
GUI:setTouchEnabled(tips_img, false)
GUI:setTag(tips_img, 0)
local Text_1 = GUI:Text_Create(tips_layout, "zs_Text_1", 260, 110, 34, "#b9b900", [[文本]])
GUI:Text_enableOutline(Text_1, "#000000", 1)
GUI:setAnchorPoint(Text_1, 0.00, 0.00)
GUI:setTouchEnabled(Text_1, false)
GUI:setTag(Text_1, 0)
GUI:Text_setString(Text_1, curLevel)
-- 使用正确的动作序列实现延时淡出动画
local function fadeOutCallback()
if GUI:Win_IsNotNull(tips_layout) then
GUI:removeFromParent(tips_layout)
SL:Print("tips_layout 已移除")
end
end
-- 创建动作序列:延时2秒 -> 淡出1秒 -> 回调移除
local actionSequence = GUI:ActionSequence(
GUI:DelayTime(2), -- 延时2秒
GUI:ActionFadeOut(1), -- 淡出动作,持续1秒
GUI:CallFunc(fadeOutCallback) -- 淡出后回调移除控件
)
-- 运行动作序列
GUI:runAction(tips_layout, actionSequence)
SL:Print("===================3333333333333333333")
end
```
**修改说明:**
1. 移除了自定义函数 `lib:widget_popUp_move_to_fadeout`,直接使用引擎提供的动作函数。
2. 使用 `GUI:DelayTime(2)` 创建2秒的延时动作。
3. 使用 `GUI:ActionFadeOut(1)` 创建1秒的淡出动作。
4. 使用 `GUI:ActionSequence` 将延时、淡出和回调动作组合成顺序播放的序列。
5. 在回调函数中,使用 `GUI:removeFromParent(tips_layout)` 安全移除控件。
**注意:** 确保在运行动作前,控件已正确创建并添加到父节点。如果动画仍无延时,请检查是否有其他代码在干扰动作执行,比如重复调用了 `GUI:runAction` 或使用了 `GUI:stopAllActions`。不懂的可以问浮生梦老师!
你的代码中,`lib:widget_popUp_move_to_fadeout(tips_layout)` 这行调用的自定义函数可能没有正确设置延时动作。根据浮生梦老师前端课程内容,动画延时需要使用 `GUI:DelayTime(time)` 来创建延时动作,并组合到动作序列中。
以下是修改后的 `zhuansheng.tigger_tips` 函数,确保动画有延时效果:
```lua
function zhuansheng.tigger_tips()
local ui = zhuansheng.parent._ui
local parent = ui.ImageView
local curLevel = lib:get_zs_level() or 0
local old_layout = GUI:getChildByName(parent, "zs_tips_layout")
SL:Print("GUI:Win_IsNull(old_layout)=", GUI:Win_IsNull(old_layout))
if GUI:Win_IsNotNull(old_layout) then
local text = GUI:getChildByName(old_layout, "zs_Text_1")
SL:Print("GUI:Win_IsNull(text)=", GUI:Win_IsNull(text))
if text then
GUI:Text_setString(text, curLevel)
end
SL:Print("111111111111")
return
end
-- Create tips_layout
local tips_layout = GUI:Layout_Create(parent, "zs_tips_layout", 0, 0, 246, 368, false)
GUI:setAnchorPoint(tips_layout, 0.00, 0.00)
GUI:setTouchEnabled(tips_layout, false)
GUI:setTag(tips_layout, 0)
-- Create tips_eff
local tips_eff = GUI:Effect_Create(tips_layout, "zs_tips_eff", 252, 202, 0, 86416, 0, 0, 0, 1)
GUI:setTag(tips_eff, 0)
-- Create tips_img
local tips_img = GUI:Image_Create(tips_layout, "zs_tips_img", 0, 0, "res/yidalu/zhuansheng4.0/zhuansheng tup.png")
GUI:setAnchorPoint(tips_img, 0.00, 0.00)
GUI:setTouchEnabled(tips_img, false)
GUI:setTag(tips_img, 0)
local Text_1 = GUI:Text_Create(tips_layout, "zs_Text_1", 260, 110, 34, "#b9b900", [[文本]])
GUI:Text_enableOutline(Text_1, "#000000", 1)
GUI:setAnchorPoint(Text_1, 0.00, 0.00)
GUI:setTouchEnabled(Text_1, false)
GUI:setTag(Text_1, 0)
GUI:Text_setString(Text_1, curLevel)
-- 使用正确的动作序列实现延时淡出动画
local function fadeOutCallback()
if GUI:Win_IsNotNull(tips_layout) then
GUI:removeFromParent(tips_layout)
SL:Print("tips_layout 已移除")
end
end
-- 创建动作序列:延时2秒 -> 淡出1秒 -> 回调移除
local actionSequence = GUI:ActionSequence(
GUI:DelayTime(2), -- 延时2秒
GUI:ActionFadeOut(1), -- 淡出动作,持续1秒
GUI:CallFunc(fadeOutCallback) -- 淡出后回调移除控件
)
-- 运行动作序列
GUI:runAction(tips_layout, actionSequence)
SL:Print("===================3333333333333333333")
end
```
**修改说明:**
1. 移除了自定义函数 `lib:widget_popUp_move_to_fadeout`,直接使用引擎提供的动作函数。
2. 使用 `GUI:DelayTime(2)` 创建2秒的延时动作。
3. 使用 `GUI:ActionFadeOut(1)` 创建1秒的淡出动作。
4. 使用 `GUI:ActionSequence` 将延时、淡出和回调动作组合成顺序播放的序列。
5. 在回调函数中,使用 `GUI:removeFromParent(tips_layout)` 安全移除控件。
**注意:** 确保在运行动作前,控件已正确创建并添加到父节点。如果动画仍无延时,请检查是否有其他代码在干扰动作执行,比如重复调用了 `GUI:runAction` 或使用了 `GUI:stopAllActions`。不懂的可以问浮生梦老师!
← 返回问答库