TweenService

非推奨を表示

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。

作成できません
サービス

TweenService は、インスタンスのプロパティをインターポリровать、またはTweens を作成するために使用されます。Tweens は、互換性のあるプロパティタイプを持つすべてのオブジェクトに使用できます、包括:

TweenService:Create() 、主なコンストラクター機能、tween に関する TweenInfo の仕様を取得し、Tween オブジェクトを生成し、斑点を再生するために使用できます。

注:Tweens は、複数のプロパティを同時にインターポリроваることができますが、同じプロパティをインターポリしてはなりません。ツイーンが同じプロパティを変更しようとした場合、最初のツイーンはキャンセルされ、最新のツイーンに上書きされます。

コードサンプル

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

コンストラクター Create() は、3つの引数から新しい Tween を作成します:オブジェクトのツイーン、TweenInfo の特定、および減算値を拡張するためのテーブル。

PropertyTable パラメーターは、キーがプロパティの名前のストリング名であるダイクションになる必要があります(例えば PositionTransparency 、または 1>Color1>)、および値は減算後のプロパティターゲットです。

この関数を使用して作成された Class.Tween は、insインスタンス パラメーターとして与えられたオブジェクトにユニークです。同じ tween を別のオブジェクトに適用するには、新しいオブジェクトでこの関数を再び呼び出します。

パラメータ

instance: Instance

Class.Instance のプロパティをツイーンする

tweenInfo: TweenInfo

使用する TweenInfo

propertyTable: Dictionary

プロパティの辞書とそのターゲット値をツイーンするためのダイダクト。


戻り値

コードサンプル

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

ENSEARCH.EASING.COLON 、Enum.EasingDirectionalpha 、1>ENSEARCH.EASING. EasingDirection1> を使用して、インターポリングする新しいアルファ値を返します。提供された 4>Alpha4> 値は、7>07> と 9>19>

パラメータ

alpha: number

0 と 1 の間のインタープレーション値。

easingStyle: Enum.EasingStyle

使用する簡素化スタイル。

easingDirection: Enum.EasingDirection

使用する矢印の向き。


戻り値

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

SmoothDamp

パラメータ

current: Variant
target: Variant
velocity: Variant
smoothTime: number
maxSpeed: number
dt: number

戻り値

イベント