Tween
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
วัตถุ Tween ควบคุมการเล่นของการ interpolationการสร้างและกำหนดค่า ทำด้วยฟังก์ชัน ไม่สามารถใช้กับวัตถุเฉพาะนี้ได้
โปรดทราบว่าแม้ว่าการกำหนดค่าของวัยรุ่นจะสามารถเข้าถึงได้หลังจากที่วัยรุ่นถูกสร้างขึ้นแล้ว ก็ไม่สามารถแก้ไขได้หากต้องการเป้าหมายใหม่สำหรับการ interpolation จะต้องสร้าง 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()
สรุป
คุณสมบัติ
คุณสมบัติอ่านเฉพาะที่ชี้ไปที่ Instance ซึ่งคุณสมบัติจะถูกแทรกโดย tween
คุณสมบัติอ่านเฉพาะที่รวมข้อมูลเกี่ยวกับวิธีการใช้ interpolation ของ Tween ที่จะดำเนินการ
แอนิเมชันTween
วิธีการ
วิธีการรับทอดมาจาก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)