TweenService

Mostrar obsoleto

*Pronto este contenido estará disponible en tu idioma seleccionado.

No creable
Servicio

TweenService is used to create Tweens which interpolate, or tween, the properties of instances. Tweens can be used on any object with compatible property types, including:

TweenService:Create(), the primary constructor function, takes TweenInfo specifications about the tween and generates the Tween object which can then be used to play the tween.

Note that Tweens can interpolate multiple properties at the same time, but they must not be interpolating the same property. If two tweens attempt to modify the same property, the initial tween will be cancelled and overwritten by the most recent tween.

Muestras de código

Tween Creation

local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Position = Vector3.new(0, 10, 0)
part.Color = Color3.new(1, 0, 0)
part.Anchored = true
part.Parent = game.Workspace
local goal = {}
goal.Position = Vector3.new(10, 10, 0)
goal.Color = Color3.new(0, 1, 0)
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
Looping a Tween

local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Position = Vector3.new(0, 10, 0)
part.Anchored = true
part.Parent = workspace
local tweenInfo = TweenInfo.new(
2, -- Time
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
true, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local tween = TweenService:Create(part, tweenInfo, { Position = Vector3.new(0, 30, 0) })
tween:Play()
task.wait(10)
tween:Cancel() -- cancel the animation after 10 seconds
Pausing a Tween

local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Position = Vector3.new(0, 10, 0)
part.Anchored = true
part.BrickColor = BrickColor.new("Bright green")
part.Parent = workspace
local goal = {}
goal.Position = Vector3.new(50, 10, 0)
local tweenInfo = TweenInfo.new(10, Enum.EasingStyle.Linear)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.wait(3)
part.BrickColor = BrickColor.new("Bright red")
tween:Pause()
task.wait(2)
part.BrickColor = BrickColor.new("Bright green")
tween:Play()

Resumen

Métodos

Propiedades

Métodos

Create

This constructor creates a new Tween from three arguments: the object to tween, the TweenInfo specifications, and a table containing the properties to tween and values to tween to.

The propertyTable parameter needs to be a dictionary where the keys are the string names of the property (for example Position, Transparency, or Color), and the values are the property targets at the end of the tween.

The Tween created using this function is unique to the object given as the instance parameter. To apply the same tween to another object, call this function again with the new object.

Parámetros

instance: Instance

The Instance whose properties are to be tweened.

tweenInfo: TweenInfo

The TweenInfo to be used.

propertyTable: Dictionary

A dictionary of properties, and their target values, to be tweened.


Devuelve

Muestras de código

Tween Creation

local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Position = Vector3.new(0, 10, 0)
part.Color = Color3.new(1, 0, 0)
part.Anchored = true
part.Parent = game.Workspace
local goal = {}
goal.Position = Vector3.new(10, 10, 0)
goal.Color = Color3.new(0, 1, 0)
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
Looping a Tween

local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Position = Vector3.new(0, 10, 0)
part.Anchored = true
part.Parent = workspace
local tweenInfo = TweenInfo.new(
2, -- Time
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
true, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local tween = TweenService:Create(part, tweenInfo, { Position = Vector3.new(0, 30, 0) })
tween:Play()
task.wait(10)
tween:Cancel() -- cancel the animation after 10 seconds

GetValue

Returns a new alpha value for interpolating using the given alpha value, Enum.EasingStyle, and Enum.EasingDirection. The provided alpha value will be clamped between 0 and 1.

Parámetros

alpha: number

An interpolation value between 0 and 1.

easingStyle: Enum.EasingStyle

The easing style to use.

easingDirection: Enum.EasingDirection

The easing direction to use.


Devuelve

A new alpha value generated from the given easing style and direction.

SmoothDamp

Returns a value that allows smoothing a value towards a target simulating a critically damped spring. Supports Vector2, Vector3, and CFrame, and number.

Parámetros

current: Variant
target: Variant
velocity: Variant
smoothTime: number
maxSpeed: number
dt: number

Devuelve

Eventos