Tween

แสดงที่เลิกใช้งานแล้ว

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่

วัตถุ Tween ควบคุมการเล่นของการแปลง การสร้างและการกำหนดค่าของ Tween เสร็จสิ้นด้วย función TweenService:Create() ; 1> Datatype.Instance.new()1> ไม่สามารถใช้สำหรั

หมายเหตุว่าขณะที่การกำหนดค่าของ tween สามารถเข้าถึงได้หลังจากที่ tween ได้รับการสร้างขึ้น มันไม่สามารถเปลี่ยนแปลงได้ หากมีเป้าหมายใหม่สำหรับการแปลง ใหม่ 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()

สรุป

คุณสมบัติ

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    สมบัติที่อ่านเท่านั้นที่ชี้ไปที่ Instance ซึ่งสมบัติของมันกำลังถูกส่งผ่านโดย tween

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    สมบัติที่อ่านเท่านั้นที่รวมถึงข้อมูลเกี่ยวกับวิธีการที่การแปลงของ Tween จะดำเนินการ

คุณสมบัติรับทอดมาจากTweenBase
  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    สิ่งที่อ่านเท่านั้นที่แสดงสถานะปัจจุบันสำหรับอนิเมชัน Tween

วิธีการ

วิธีการรับทอดมาจากTweenBase
  • Cancel():()

    หยุดการเล่นและรีเซ็ตตัวแปรทวีนส์ หากคุณโทร TweenBase:Play() คุณสมบัติของ tween จะเริ่มต้นอินเทอร์โพลต่อไปยังจุดหมายปลายทางของพวกเขา แต่ใช้ความยาวของอนิเมชันเพื่อทำเช่นนั้น

  • Pause():()

    หยุดการเล่นของ tween ไม่รีเซ็ตตัวแปรความคืบหน้าของ tween ซึ่งหมายความว่าหากคุณเรียก TweenBase:Play() จะเริ่มเล่นตั้งแต่ที่มันถูกหยุด

  • Play():()

    เริ่มเล่นของ tween หากเล่นแล้วเริ่มต้นแล้ว การโทร Play() ไม่มีผล ยกเว้น tween จะเสร็จสิ้นหรือถูกหยุด (โดย TweenBase:Cancel() หรือ TweenBase:Pause() )

อีเวนต์

อีเวนต์รับทอดมาจากTweenBase

คุณสมบัติ

Instance

อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

สมบัติของ Instance (อ่านเท่านั้น) ที่ชี้ไปที่ Tween ซึ่งสมบัติของมันกำลังถูกส่งผ่าน

ตัวอย่างโค้ด

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 พิมพ์TweenInfo

ตัวอย่างโค้ด

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)

วิธีการ

อีเวนต์