Tween

Tampilkan yang Tidak Digunakan Lagi

*Konten ini diterjemahkan menggunakan AI (Beta) dan mungkin mengandung kesalahan. Untuk melihat halaman ini dalam bahasa Inggris, klik di sini.

Objek Tween mengontrol pemutaran interpolasi.Membuat dan mengkonfigurasi Tween adalah dilakukan dengan fungsi TweenService:Create(); Instance.new() tidak dapat digunakan untuk objek khusus ini.

Perhatikan bahwa meskipun konfigurasi tween dapat diakses setelah tween dibuat, tidak dapat dimodifikasi.Jika tujuan baru diperlukan untuk interpolasi, harus dibuat Tween baru.

Perhatikan juga bahwa beberapa remaja dapat dimainkan pada objek yang sama pada saat yang sama, tetapi mereka tidak boleh menginterpolasi properti yang sama.Jika dua remaja mencoba memodifikasi properti yang sama, tween awal akan dibatalkan dan ditulis ulang oleh tween terbaru.

Contoh Kode

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

Rangkuman

Properti

  • Hanya Baca
    Tidak Direplikasi
    Baca Paralel

    Properti hanya baca yang menunjuk ke Instance yang propertinya disingkirkan oleh tween.

  • Hanya Baca
    Tidak Direplikasi
    Baca Paralel

    Properti hanya baca yang berisi informasi tentang bagaimana interpolasi dari Tween dilakukan.

Properti diwarisi dari TweenBase

Metode

Metode diwarisi dari TweenBase
  • Cancel():()

    Memhentikan pemutaran dan mengatur ulang variabel remaja.Jika Anda kemudian memanggil TweenBase:Play(), properti tween melanjutkan interpolasi menuju tujuan mereka, tetapi ambil seluruh panjang animasi untuk melakukannya.

  • Pause():()

    Menghentikan pemutaran tween.Tidak mengatur ulang variabel kemajuan, artinya jika Anda memanggil TweenBase:Play(), tween akan melanjutkan pemutaran dari saat dijeda.

  • Play():()

    Memulai pemutaran seorang remaja.Perhatikan bahwa jika pemutaran sudah dimulai, memanggil Play() tidak berpengaruh kecuali remaja telah selesai atau dihentikan (baik oleh TweenBase:Cancel() atau TweenBase:Pause() ).

Acara

Acara diwarisi dari TweenBase

Properti

Instance

Hanya Baca
Tidak Direplikasi
Baca Paralel

Properti ini dari Tween (baca hanya) menunjuk ke Instance yang propertinya disingkirkan.

Contoh Kode

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

Hanya Baca
Tidak Direplikasi
Baca Paralel

Properti hanya baca yang berisi informasi tentang bagaimana interpolasi dari Tween dilakukan, menggunakan jenis data TweenInfo.

Contoh Kode

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)

Metode

Acara