TweenService

TweenService 是 Roblox 中的一個服務,允許您為 GUI 元素、部件和其他對象創建流暢的動畫。它用於在指定的持續時間內將對象的屬性從一個狀態插值到另一個狀態。

TweenTween 是一個動畫,它將對象的屬性從起始狀態插值到結束狀態。
TweenInfo這定義了 tween 的參數,例如持續時間、緩動樣式、緩動方向和重複。
緩動樣式和方向緩動樣式定義了用於在 tween 的起始值和結束值之間插值的數學函數。緩動方向定義了 tween 如何相對於起始值和結束值進行。

可緩動對象

Position將部件/模型移動到新位置。
Size更改部件/模型的尺寸。
Orientation旋轉部件/模型。
Transparency調整部件/模型的透明度。
Color更改部件/模型的顏色。
Position將部件/模型移動到新位置。
Size更改部件/模型的尺寸。
BackgroundColor3更改 GUI 元素的背景顏色。
Transparency調整部件/模型的透明度。
Brightness調整光源的亮度。
Color更改部件/模型的顏色。
Range更改光源的範圍。
CFrame移動或旋轉攝像機。
Volume調整聲音的音量。
PlaybackSpeed更改聲音的播放速度。

TweenService 示例

緩動位置

local TweenService = game:GetService("TweenService")

-- Define TweenInfo
local tweenInfo = TweenInfo.new(
	2, -- Time (seconds)
	Enum.EasingStyle.Quad, -- Easing Style
	Enum.EasingDirection.Out, -- Easing Direction
	0, -- Repeat count (0 means no repeat)
	false, -- Reverses (tween goes back and forth)
	0 -- Delay time (seconds)
)

local part = script.Parent
part.Position = Vector3.new(0, 2.5, 0)
part.Anchored = true
part.Parent = workspace

-- Define the end state of the properties you want to tween
local goal = {}
goal.Position = Vector3.new(10, 5, 0)

-- Create the tween
local tween = TweenService:Create(part, tweenInfo, goal)

-- Play the tween
tween:Play()
Image 1
Roblox Studio

緩動 GUI 元素

local TweenService = game:GetService("TweenService")

-- Define TweenInfo
local tweenInfo = TweenInfo.new(
	2, -- Time (seconds)
	Enum.EasingStyle.Quad, -- Easing Style
	Enum.EasingDirection.Out, -- Easing Direction
	0, -- Repeat count (0 means no repeat)
	false, -- Reverses (tween goes back and forth)
	0 -- Delay time (seconds)
)

local part = script.Parent
part.Position = Vector3.new(0, 2.5, 0)
part.Anchored = true
part.Parent = workspace

-- Define the end state of the properties you want to tween
local goal = {}
goal.Position = Vector3.new(10, 5, 0)

-- Create the tween
local tween = TweenService:Create(part, tweenInfo, goal)

-- Play the tween
tween:Play()
Image 1
Roblox Studio

緩動光源屬性

local TweenService = game:GetService("TweenService")

-- Define TweenInfo
local tweenInfo = TweenInfo.new(
	2, -- Time (seconds)
	Enum.EasingStyle.Quad, -- Easing Style
	Enum.EasingDirection.Out, -- Easing Direction
	0, -- Repeat count (0 means no repeat)
	false, -- Reverses (tween goes back and forth)
	0 -- Delay time (seconds)
)

local part = script.Parent
part.Position = Vector3.new(0, 2.5, 0)
part.Anchored = true
part.Parent = workspace

-- Define the end state of the properties you want to tween
local goal = {}
goal.Position = Vector3.new(10, 5, 0)

-- Create the tween
local tween = TweenService:Create(part, tweenInfo, goal)

-- Play the tween
tween:Play()
Image 1
Roblox Studio

緩動樣式

Linear從開始到結束以恆定速度移動。
Sine使用正弦波實現平滑、周期性的運動。
Back在到達終點前超出,然後回落到終點。
Quad快速加速,然後逐漸減速。
Cubic類似於 Quad,但具有更強的加速和減速效果。
Quart比 Cubic 更強的加速和減速效果。
Quint最強的加速和減速效果。
Bounce模仿結束時的彈跳效果。
Elastic以彈簧般的方式超出終點,然後回落。
Exponential起初緩慢,然後呈指數級加速。
In緩慢開始,在結束時加速。
Out快速開始,在結束時減速。
InOut結合了 'In' 和 'Out' 的特點,開始緩慢,中間加速,結束時再次減速。

如果你覺得這個教程對你有幫助,並且願意支持我的工作,請考慮請我飲杯咖啡。

非常感謝你的支持!

請我飲杯咖啡