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.
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
이 생성자는 세 가지 인수에서 새로운 Tween를 생성합니다: 전환할 개체, TweenInfo 사양 및 전환할 속성과 전환할 값을 포함하는 테이블.
propertyTable 매개 변수는 키가 속성의 문자열 이름인 사전이어야 하며(예: Position, Transparency, 또는 Color ), 값은 십대의 끝에 있는 속성 대상입니다.
이 함수를 사용하여 생성된 Tween 는 매개 변수 instance 로 지정된 개체와 유일하게 일치합니다.동일한 십대를 다른 개체에 적용하려면 새 개체로 이 함수를 다시 호출하십시오.
매개 변수
중간에 전환될 속성 및 대상 값의 사전.
반환
코드 샘플
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 , 그리고 숫자.
매개 변수
현재 위치.
대상 위치.
현재 위치가 대상 위치에 접근해야 하는 초기 속도입니다.
전체 부드러움 작업이 플레이스기간.
현재 위치가 대상 위치에 접근할 수 있는 최대 속도.
부드러움 작업이 적용되는 속도.
반환
부드러움 작업에서 계산된 새로운 위치와 속도.