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' 的特点,开始缓慢,中间加速,结束时再次减速。

如果您觉得本教程对您有帮助,并且愿意支持我的工作,请考虑请我喝杯咖啡。

非常感谢您的支持!

请我喝咖啡