Engine Class
TweenService
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
สรุป
วิธีการ
Create(instance: Instance,tweenInfo: TweenInfo,propertyTable: Dictionary):Tween |
GetValue(alpha: number,easingStyle: Enum.EasingStyle,easingDirection: Enum.EasingDirection):number |
SmoothDamp(current: Variant,target: Variant,velocity: Variant,smoothTime: number,maxSpeed: number?,dt: number?):Tuple |
ตัวอย่างโค้ด
การสร้าง Tween
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()การลูปทวิน
local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Position = Vector3.new(0, 10, 0)
part.Anchored = true
part.Parent = workspace
local tweenInfo = TweenInfo.new(
2, -- เวลา
Enum.EasingStyle.Linear, -- รูปแบบการทำให้เรียบ
Enum.EasingDirection.Out, -- ทิศทางการทำให้เรียบ
-1, -- จำนวนการทำซ้ำ (เมื่อต่ำกว่า 0 ทวินจะลูปต่อเนื่อง)
true, -- กลับหลัง (ทวินจะกลับหลังเมื่อถึงจุดหมาย)
0 -- เวลาหน่วง
)
local tween = TweenService:Create(part, tweenInfo, { Position = Vector3.new(0, 30, 0) })
tween:Play()
task.wait(10)
tween:Cancel() -- ยกเลิกการอนิเมชั่นหลังจาก 10 วินาทีการหยุดทเวล
local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Position = Vector3.new(0, 10, 0)
part.Anchored = true
part.BrickColor = BrickColor.new("Bright green")
part.Parent = workspace
local goal = {}
goal.Position = Vector3.new(50, 10, 0)
local tweenInfo = TweenInfo.new(10, Enum.EasingStyle.Linear)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.wait(3)
part.BrickColor = BrickColor.new("Bright red")
tween:Pause()
task.wait(2)
part.BrickColor = BrickColor.new("Bright green")
tween:Play()เอกสารอ้างอิงเกี่ยวกับ API
วิธีการ
Create
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
การสร้าง Tween
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()การลูปทวิน
local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Position = Vector3.new(0, 10, 0)
part.Anchored = true
part.Parent = workspace
local tweenInfo = TweenInfo.new(
2, -- เวลา
Enum.EasingStyle.Linear, -- รูปแบบการทำให้เรียบ
Enum.EasingDirection.Out, -- ทิศทางการทำให้เรียบ
-1, -- จำนวนการทำซ้ำ (เมื่อต่ำกว่า 0 ทวินจะลูปต่อเนื่อง)
true, -- กลับหลัง (ทวินจะกลับหลังเมื่อถึงจุดหมาย)
0 -- เวลาหน่วง
)
local tween = TweenService:Create(part, tweenInfo, { Position = Vector3.new(0, 30, 0) })
tween:Play()
task.wait(10)
tween:Cancel() -- ยกเลิกการอนิเมชั่นหลังจาก 10 วินาทีGetValue
TweenService:GetValue(
พารามิเตอร์
ส่งค่ากลับ