TweenService

사용되지 않는 항목 표시

*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.

만들 수 없음
서비스

TweenService 는 속성을 인스턴스에 대해 인터폴레이션하거나 트윈하는 속성을 만드는 데 사용됩니다. Tweens 은 다음과 같은 속성을 가진 모든 개체에 사용할 수 있습니다.

TweenService:Create() , 주 생성자 함수, tween에 대한 TweenInfo 사양을 가져와 트위인을 생성하고, 생성된 트위인 개체를 사용하여 트위인을 플레이할 수 있습니다.

Class.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()를 생성합니다. 개체를 트위니고, Tween 사양 및 트위니고 및 값을 지정하는 테이블을 포함하는 속성을 만듭니다.

속성 테이블 매개 변수는 속성의 키가 문자열인 사전이어야 하며(예: Position, Transparency, 또는 1>Color1>), 값은 트윈의 끝에 있는 속성 대상입니다.

이 함수를 사용하여 생성된 Tween 은 개체에 주어진 instance 매개 변수를 사용하는 독점적인 개체입니다. 다른 개체에 동일한 트윈을 적용하려면 새 개체와 이 함수를 다시 호출하십시오.

매개 변수

instance: Instance

속성을 트위니드해야 하는 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

지정된 알파 값을 사용하여 인터폴레이션을 수행하는 경우 알파 값 반환, Enum.EasingStyleEnum.EasingDirection 을 포함하여 제공된 알파 값 값이 alpha 및 1> 11> 사이에 조정됩니다. 제공된 4> alpha4> 값은

매개 변수

alpha: number

0 와 1 사이의 인터플레이션 값.

easingStyle: Enum.EasingStyle

사용하기 쉬운 스타일.

easingDirection: Enum.EasingDirection

사용하기 쉬운 방향.


반환

지정된 쉬핑 스타일과 방향에서 생성된 새로운 알파 값.

SmoothDamp

매개 변수

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

반환

이벤트