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.

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()

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.

Looping a Tween

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.

Pausing a Tween

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()

概要

方法

プロパティ

方法

Create

このコンストラクタは、3つの引数から新しい Tween を作成します:ターンするオブジェクト、TweenInfo 仕様、そしてターンするプロパティと値を含むテーブル。

propertyTable パラメータは、キーがプロパティのストリング名である辞書である必要があり(例えば PositionTransparency 、または Color )、値は減衰の終わりにプロパティターゲットです。

この関数を使用して作成された Tween は、instance パラメータとして指定されたオブジェクトと唯一です。同じ tween を別のオブジェクトに適用するには、新しいオブジェクトでこの関数を再度呼び出します。

パラメータ

instance: Instance

プロパティが減衰する必要がある Instance の。

既定値: ""
tweenInfo: TweenInfo

使用する TweenInfo

既定値: ""
propertyTable: Dictionary

中断するプロパティとターゲット値の辞書。 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.

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()

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.

Looping a Tween

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 値は、01 の間にクリップされます。

パラメータ

alpha: number

01 の間のインターポレーション値。

既定値: ""
easingStyle: Enum.EasingStyle

使用する緩和スタイル。

既定値: ""
easingDirection: Enum.EasingDirection

使用する緩和方向。

既定値: ""

戻り値

指定された緩和スタイルと方向から生成された新しいアルファ値。

SmoothDamp

並列書き込み

値をターゲットにスムーズすることができるトゥプルを返し、クリティカルダンプのスプリングをシミュレートします。サポート Vector2 , Vector3 , CFrame , そして数。

パラメータ

current: Variant

現在の位置。

既定値: ""
target: Variant

ターゲットの位置。

既定値: ""
velocity: Variant

現在の位置がターゲットポジションに接近する初期速度。

既定値: ""
smoothTime: number

総スムージング操作が行われる期間。

既定値: ""
maxSpeed: number

現在の位置がターゲットの位置に接近する最大速度。

既定値: ""
dt: number

スムージング操作が適用される率。

既定値: ""

戻り値

スムージング操作から計算された新しい位置と速度。

イベント