Tween 對象控制了積分的播放。創建和配置 Tween 是使用 TweenService:Create() 函數完成的;Instance.new() 無法用於此特定物件。
請注意,雖然青少年的配置可以在青少年被創建後存取,但它不能被修改。如果需要新的目標來進行插值,必須創建新的 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.
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()
概要
方法
方法 繼承自 TweenBase暫停播放並重設暫時變量。如果您然後呼叫 TweenBase:Play(),青少年的屬性將繼續向目的地交錯,但需要全長的動畫才能這麼做。
停止青補間動畫的播放。不重置其進度變量,意味著如果您呼叫 TweenBase:Play(),青少年將從暫停播放的那一刻開始恢復播放。
開始懷舊播補間動畫。請注意,如果播放已經開始,呼叫 Play() 沒有效果,除非青少年已經完成或被停止(通過 TweenBase:Cancel() 或 TweenBase:Pause() )。
屬性
Instance
這個屬性的 Tween (只讀) 指向正在被插入的 Instance 的屬性。
範例程式碼
This code sample includes a simple function that will return true if the instance of a tween is a Part.
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
只讀屬性,包含有關如何執行 Tween 插值的信息,使用 TweenInfo 數據輸入。
範例程式碼
An example of the range of different interpolation effects that can be used in Tweens.
-- 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)