Empty
Empty
Empty
TweenService 是 Roblox 中的一个服务,允许您为 GUI 元素、部件和其他对象创建流畅的动画。它用于在指定的持续时间内将对象的属性从一个状态插值到另一个状态。
Tween | Tween 是一个动画,它将对象的属性从起始状态插值到结束状态。 |
TweenInfo | 这定义了 tween 的参数,例如持续时间、缓动样式、缓动方向和重复。 |
缓动样式和方向 | 缓动样式定义了用于在 tween 的起始值和结束值之间插值的数学函数。缓动方向定义了 tween 如何相对于起始值和结束值进行。 |
可缓动对象
Empty
Empty
Empty
Position | 将部件/模型移动到新位置。 |
Size | 更改部件/模型的尺寸。 |
Orientation | 旋转部件/模型。 |
Transparency | 调整部件/模型的透明度。 |
Color | 更改部件/模型的颜色。 |
Empty
Empty
Empty
Position | 将部件/模型移动到新位置。 |
Size | 更改部件/模型的尺寸。 |
BackgroundColor3 | 更改 GUI 元素的背景颜色。 |
Transparency | 调整部件/模型的透明度。 |
Empty
Empty
Empty
Brightness | 调整光源的亮度。 |
Color | 更改部件/模型的颜色。 |
Range | 更改光源的范围。 |
Empty
Empty
Empty
CFrame | 移动或旋转摄像机。 |
Empty
Empty
Empty
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()
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()
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()
Roblox Studio
缓动样式
Empty
Empty
Empty
Linear | 从开始到结束以恒定速度移动。 |
Sine | 使用正弦波实现平滑、周期性的运动。 |
Back | 在到达终点前超出,然后回落到终点。 |
Quad | 快速加速,然后逐渐减速。 |
Cubic | 类似于 Quad,但具有更强的加速和减速效果。 |
Quart | 比 Cubic 更强的加速和减速效果。 |
Quint | 最强的加速和减速效果。 |
Bounce | 模仿结束时的弹跳效果。 |
Elastic | 以弹簧般的方式超出终点,然后回落。 |
Exponential | 起初缓慢,然后呈指数级加速。 |
Empty
Empty
Empty
In | 缓慢开始,在结束时加速。 |
Out | 快速开始,在结束时减速。 |
InOut | 结合了 'In' 和 'Out' 的特点,开始缓慢,中间加速,结束时再次减速。 |