Tween

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

Tween 對播放器進行控制,可以在 Tween 的創建和設定。TweenService:Create() 不能對此特定對物件使用。

注意,在創建潮汐後,潮汐的設定才能被存取,但不能修改。如果需要對潮汐進行新的解釋,新的 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()

概要

屬性

  • 唯讀
    未複製
    平行讀取

    只有讀取權補間動畫的屬性,其屬性正在被減速。

  • 唯讀
    未複製
    平行讀取

    只有讀取的屬性,包含包含如何執行 Tween 的 interpolation 的信息。

屬性 繼承自 TweenBase

方法

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

    停止播放,重設暫停變數。如果你然後呼叫 TweenBase:Play(),暫停變數的屬性會恢復到其目的地,但需要完整長度的動畫才能完成。

  • Pause():void

    停止播放暫停的補間動畫。不會重設其進度變量,因此如果您呼叫 TweenBase:Play(),殺手將從暫停的那一刻起恢復播放。

  • Play():void

    開始播放擺補間動畫。注意,如果擺動已經開始,呼叫 Play() 沒有效果,除非擺動已經完成或已停止 (或由 TweenBase:Cancel()TweenBase:Pause() 來停止)。

屬性

Instance

唯讀
未複製
平行讀取

Tween 的 Tween 屬性 (只閱取) 指向其所有者的 Instance

範例程式碼

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

唯讀
未複製
平行讀取

只有可以包含 Tween 的語法變更方輸入的資訊。

範例程式碼

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)

方法

活動