TweenService
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
TweenService は、インスタンスのプロパティを交換または中間処理する Tweens を作成するために使用されます。Tweens は、次の互換可能なプロパティタイプを含む任意のオブジェクトに使用できます:
TweenService:Create() , 主なコンストラクター関数, ティーンに関する TweenInfo 仕様を受け取り、ティーンを再生するための Tween オブジェクトを生成します。
注: Tweens は同時に複数のプロパティを挿入できますが、同じプロパティを挿入してはなりません。2人のティーンが同じプロパティを変更しようとすると、最初のティーンがキャンセルされ、最新のティーンに上書きされます。
コードサンプル
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()
概要
方法
新しい Tween を作成し、プロパティが切り替えられるオブジェクト、TweenInfo 、および目標のプロパティ値の辞書を指定します。
- GetValue(alpha : number,easingStyle : Enum.EasingStyle,easingDirection : Enum.EasingDirection):number
Enum.EasingStyle と Enum.EasingDirection を与えられた新しいアルファを計算します。
- SmoothDamp(current : Variant,target : Variant,velocity : Variant,smoothTime : number,maxSpeed : number?,dt : number?):Tuple
クリティカルダンプのスプリングをシミュレートする値を計算します。
プロパティ
方法
Create
このコンストラクタは、3つの引数から新しい Tween を作成します:ターンするオブジェクト、TweenInfo 仕様、そしてターンするプロパティと値を含むテーブル。
propertyTable パラメータは、キーがプロパティのストリング名である辞書である必要があり(例えば Position 、Transparency 、または Color )、値は減衰の終わりにプロパティターゲットです。
この関数を使用して作成された Tween は、instance パラメータとして指定されたオブジェクトと唯一です。同じ tween を別のオブジェクトに適用するには、新しいオブジェクトでこの関数を再度呼び出します。
パラメータ
中断するプロパティとターゲット値の辞書。 dictionary of properties, and their target values, to be tweened.
戻り値
コードサンプル
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
指定されたアルファ値を使用してインターポレーションすると、新しいアルファ値を返します、Enum.EasingStyle、および Enum.EasingDirection。提供された alpha 値は、0 と 1 の間にクリップされます。
パラメータ
0 と 1 の間のインターポレーション値。
使用する緩和スタイル。
使用する緩和方向。
戻り値
指定された緩和スタイルと方向から生成された新しいアルファ値。
SmoothDamp
値をターゲットにスムーズすることができるトゥプルを返し、クリティカルダンプのスプリングをシミュレートします。サポート Vector2 , Vector3 , CFrame , そして数。
パラメータ
現在の位置。
ターゲットの位置。
現在の位置がターゲットポジションに接近する初期速度。
総スムージング操作が行われる期間。
現在の位置がターゲットの位置に接近する最大速度。
スムージング操作が適用される率。
戻り値
スムージング操作から計算された新しい位置と速度。