Tween

顯示已棄用項目

*此內容很快就會推出您所選的語言版本。

The Tween object controls the playback of an interpolation. Creating and configuring a Tween is done with the TweenService:Create() function; Instance.new() cannot be used for this particular object.

Note that while the configuration of a tween can be accessed after a tween has been created, it can not be modified. If new goals are needed for an interpolation, a new Tween must be created.

Also note that multiple tweens can be played on the same object 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.

範例程式碼

In this example a Tween is created to animate the position and color of a Part. Because the position and color are part of the same tween, they will change at the exact same rate and will reach their goal at the same time.

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()

概要

屬性

  • 唯讀
    未複製
    平行讀取

    Read-only property that points to the Instance whose properties are being interpolated by the tween.

  • 唯讀
    未複製
    平行讀取

    Read-only property that includes information on how the interpolation of the Tween is to be carried out.

屬性 繼承自 TweenBase

方法

方法 繼承自 TweenBase
  • Cancel():void

    Halts playback and resets the tween variables. If you then call TweenBase:Play(), the properties of the tween resume interpolating towards their destination, but take the full length of the animation to do so.

  • Pause():void

    Halts playback of the tween. Doesn't reset its progress variables, meaning that if you call TweenBase:Play(), the tween resumes playback from the moment it was paused.

  • Play():void

    Starts playback of a tween. Note that if playback has already started, calling Play() has no effect unless the tween has finished or is stopped (either by TweenBase:Cancel() or TweenBase:Pause()).

活動

活動 繼承自 TweenBase

屬性

Instance

唯讀
未複製
平行讀取

This property of a Tween (read-only) points to the Instance whose properties are being interpolated.

範例程式碼

This code sample includes a simple function that will return true if the instance of a tween is a Part.

Tween Instance

local TweenService = game:GetService("TweenService")
local function isInstanceAPart(tween)
local instance = tween.Instance
return instance:IsA("BasePart")
end
local tweenInfo = TweenInfo.new()
local instance = Instance.new("Part")
local tween = TweenService:Create(instance, tweenInfo, {
Transparency = 1,
})
print(isInstanceAPart(tween))

TweenInfo

唯讀
未複製
平行讀取

Read-only property that includes information on how the interpolation of the Tween is to be carried out, using the TweenInfo data type.

範例程式碼

An example of the range of different interpolation effects that can be used in Tweens.

TweenInfo Examples

-- A TweenInfo with all default parameters
TweenInfo.new()
-- A TweenInfo with its time set to 0.5 seconds.
TweenInfo.new(0.5)
-- A TweenInfo with its easing style set to Back.
TweenInfo.new(0.5, Enum.EasingStyle.Back)
-- A TweenInfo with its easing direction set to In.
TweenInfo.new(0.5, Enum.EasingStyle.Back, Enum.EasingDirection.In)
-- A TweenInfo that repeats itself 4 times.
TweenInfo.new(0.5, Enum.EasingStyle.Back, Enum.EasingDirection.In, 4)
-- A TweenInfo that reverses its interpolation after reaching its goal.
TweenInfo.new(0.5, Enum.EasingStyle.Back, Enum.EasingDirection.In, 4, true)
-- A TweenInfo that loops indefinitely.
TweenInfo.new(0.5, Enum.EasingStyle.Back, Enum.EasingDirection.In, -1, true)
-- A TweenInfo with a delay of 1 second between each interpolation.
TweenInfo.new(0.5, Enum.EasingStyle.Back, Enum.EasingDirection.In, 4, true, 1)

方法

活動