如何在 ROBLOX 中的缓动之后触发函数

有人知道如何在缓动之后触发函数调用吗?我想在缓动停止后显示一些文本。

点赞
用户88888888
用户88888888

你必须在tweeninfo变量中设置缓动时间。只需使用wait()等待与缓动播放()时间相同的时间,然后触发一个函数。

2020-06-11 11:38:29
用户2860267
用户2860267

Tween 中带有 Completed 事件,并且您可以将回调函数附加到它上面。

在 LocalScript 中,您可以有以下内容:

local TweenService = game:GetService("TweenService")

-- 找到要动画的 GUI 元素
local lp = game.Players.LocalPlayer
local exampleScreen = Instance.new("ScreenGui", lp.PlayerGui)
exampleScreen.Name = "Example"
local label = Instance.new("TextLabel")
label.Position = UDim2.new(0,0,0,0)
label.Size = UDim2.new(0, 10, 0, 10)
label.Parent = exampleScreen

-- 选择要动画的一些属性
local goal = {}
goal.Position = UDim2.new(0.5, -20, 0.5, -100)
goal.Size = UDim2.new(0.5, 40, 0.5, 200)

-- 创建 Tween
local time = 5 --seconds
local tweenInfo = TweenInfo.new(time)
local tween = TweenService:Create(label, tweenInfo, goal)

-- 监听 Tween 完成事件
tween.Completed:Connect( function(tweenState)
    label.Text = "Tween Completed"
end)

-- 播放 Tween
tween:Play()
2020-06-11 16:30:48