TweenService

사용되지 않는 항목 표시

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

만들 수 없음
서비스

TweenService는 인스턴스의 속성을 중간화하거나 전환하는 Tweens를 생성하는 데 사용됩니다.Tweens 호환되는 속성 유형을 포함하여 모든 개체에서 사용할 수 있습니다.

TweenService:Create() , 주 생성자 함수, 십대에 대한 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

이 생성자는 세 가지 인수에서 새로운 Tween를 생성합니다: 전환할 개체, TweenInfo 사양 및 전환할 속성과 전환할 값을 포함하는 테이블.

propertyTable 매개 변수는 키가 속성의 문자열 이름인 사전이어야 하며(예: Position, Transparency, 또는 Color ), 값은 십대의 끝에 있는 속성 대상입니다.

이 함수를 사용하여 생성된 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.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

부드러움 작업이 적용되는 속도.

기본값: ""

반환

부드러움 작업에서 계산된 새로운 위치와 속도.

이벤트