TweenService
*Bu içerik, yapay zekâ (beta) kullanılarak çevrildi ve hatalar içerebilir. Sayfayı İngilizce görüntülemek için buraya tıkla.
TweenService kullanılır toplu özellikleri yeniden düzenlemek için kullanılır. Class.Tween|Tweens``Class.Tween|Tweens 0>Class.Tween|Tweens0> 3>Class.Tween|Tweens3> 6>Class.Tween|Tweens6> TweenService9> 2>Class
TweenService:Create() , ana oluşturucu işlevi, tween hakkında TweenInfo spesifikasyonları alır ve ardından tween'i oynatmak için kullanılabilir Tween.
Not et Tweens çok sayıda özellik içerisinde aynı anda işlem yapabilir, ancak aynı özellikleri değiştirmemelidirler. Eğer iki genç aynı özelliği değiştirmeye çalışırsa, ilk tween iptal edilir ve yeni tween üzerine yazılır.
Kod Örnekleri
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()
This code sample includes an example of how a looped tween can be created. A part is instanced in the Workspace and a Tween is created using TweenService:Create() that is set to animate its position along the Y axis.
The looped effect is achieved by modifying the TweenInfo used in TweenService:Create(). Specifically, when RepeatCount is set to less than 0, the tween will play indefinitely. Also, setting Reverses to true will cause the tween to play in reverse once it has reached its destination. In combination this creates a looped effect.
The correct way to make a tween play indefinitely is to set RepeatCount to -1. You should avoid using large numbers or math.huge() as a substitute as this is unstable and may stop working at any point.
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, -- Time
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
true, -- Reverses (tween will reverse once reaching its goal)
0 -- DelayTime
)
local tween = TweenService:Create(part, tweenInfo, { Position = Vector3.new(0, 30, 0) })
tween:Play()
task.wait(10)
tween:Cancel() -- cancel the animation after 10 seconds
This sample demonstrates how the playback of a tween can be paused and resumed.
A part is instanced in the Workspace and a tween is setup that will move it 50 studs along the X axis. However during playback the tween is briefly paused, then resumed. To further illustrate this the BrickColor of the part changes from red to green while it is paused.
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()
Özet
Özellikler
Yöntemler
Tween edilecek öğenin özelliklerine göre yeni bir Tween oluşturur, bir TweenInfo ve hedef özellik değerleri sözlüğü.
- GetValue(alpha : number,easingStyle : Enum.EasingStyle,easingDirection : Enum.EasingDirection):number
Yeni bir alfa kullanıldığında Enum.EasingStyle ve Enum.EasingDirection .
- SmoothDamp(current : Variant,target : Variant,velocity : Variant,smoothTime : number,maxSpeed : number?,dt : number?):Tuple
Özellikler
Yöntemler
Create
The Create() constructor creates a new Tween from three arguments: the object to tween, the TweenInfo specifications, and a table containing the properties to tween and values to tween to.
PropertyTable parametresi, özelliklerin anahtarlarının özellik isimleri sözlüğü olmalıdır (örneğin Position, Transparency, veya1>Color1> ) ve değerler özellik hedefleri tween'in sonunda bulunur.
Bu işlev kullanılarak oluşturulan Tween öğesi, instance parametresi olarak verilen öğeye benzidir. Aynı tween'i başka bir öğeye uygulamak için, yeni öğeyle tekrar bu işlevi çağırın.
Parametreler
Özelliklerin ve hedef değerlerinin bir dizini, tween edilecek.
Dönüşler
Kod Örnekleri
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()
This code sample includes an example of how a looped tween can be created. A part is instanced in the Workspace and a Tween is created using TweenService:Create() that is set to animate its position along the Y axis.
The looped effect is achieved by modifying the TweenInfo used in TweenService:Create(). Specifically, when RepeatCount is set to less than 0, the tween will play indefinitely. Also, setting Reverses to true will cause the tween to play in reverse once it has reached its destination. In combination this creates a looped effect.
The correct way to make a tween play indefinitely is to set RepeatCount to -1. You should avoid using large numbers or math.huge() as a substitute as this is unstable and may stop working at any point.
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, -- Time
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
true, -- Reverses (tween will reverse once reaching its goal)
0 -- DelayTime
)
local tween = TweenService:Create(part, tweenInfo, { Position = Vector3.new(0, 30, 0) })
tween:Play()
task.wait(10)
tween:Cancel() -- cancel the animation after 10 seconds
GetValue
Verilen alfa değerini kullanarak yeniden alfa değerini işlemek için, Enum.EasingStyle ve Enum.EasingDirection . Sağlanan alpha değeri, 2> 02> ve 5> 1 5> arasında kıvrımlanacaktır.
Parametreler
0 ve 1 arasında bir çeviri değeri.
Kullanımı kolaylaştırma tarzı.
Kullanım için kolaylaştırma yönü.
Dönüşler
Verilen kolaylık tarzından ve yönünden yeni bir alfa değeri oluşturulur.