중간 변환 핸들러 사이에서 작동하는 기본 클래스; Tween 의 부모 클래스.
요약
속성
Class.Tween 애니메이션의 현재 상태를 표시하는 읽기 전용 속성입니다.
메서드
재생을 중지하고 트윈 변수를 재설정합니다. TweenBase:Play() 를 호출하면 트윈의 속성이 대상에 대해 인터폴레이션되지만, 전체 길이의 애니메이션을 수행하려면 애니메이션 길이를 가져옵니다.
트위 플레이를 중지합니다. 진행 변수를 초기화하지 않으므로 TweenBase:Play() 를 호출하면 트위 플레이가 중지된 때부터 재생됩니다.
트위니의 재생을 시작합니다. 재생이 이미 시작된 경우, Play() 을 호출하면 트위니가 완료되거나 중지(TweenBase:Cancel() 또는 TweenBase:Pause() 되지 않습니다.
이벤트
트위닝이 플레이를 완료하거나 TweenBase:Cancel() 으로 중지되면 화재됩니다.
속성
PlaybackState
Class.Tween 애니메이션의 현재 단계를 표시하는 읽기 전용 속성입니다. Enum.PlaybackState 의 설명은 Tween:Play() 의 설명과 동일합니다. 1>Class.Tween:Play1> 함수를 사용하여 변경합니다.
코드 샘플
In this example a part is rotated by a Tween back and forth several times. The TweenInfo in this case is configured to make the tween repeat twice after the first playback and pause between each playback. A function is connected to when the tween's PlaybackState changes. When run, this function will fire whenever the tween starts, pauses between playback, and ends.
local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Position = Vector3.new(0, 10, 0)
part.Anchored = true
part.Parent = workspace
local goal = {}
goal.Orientation = Vector3.new(0, 90, 0)
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 2, true, 0.5)
local tween = TweenService:Create(part, tweenInfo, goal)
local function onPlaybackChanged()
print("Tween status has changed to:", tween.PlaybackState)
end
local playbackChanged = tween:GetPropertyChangedSignal("PlaybackState")
playbackChanged:Connect(onPlaybackChanged)
tween:Play()
메서드
Cancel
Class.Tween의 재생을 중지하고 트윈 변수를 재설정합니다.
트위ン 변수만 재설정하고 트위ン으로 변경되는 속성은 재설정하지 않습니다. 애니메이션 중에 트위ン을 중간에 취소하면 속성이 원래 값으로 재설정되지 않습니다. 이 경우 TweenBase:Pause() 에서 트위ン 재설정 기간을 완료하는 데 필요한 전체 트위ン 기간을 초과합니다
반환
코드 샘플
This sample demonstrates the impact of cancelling a tween.
A part is instanced in the Workspace and a tween is set up to move it along the Y axis. Mid way through the tween, it is cancelled. It can be observed here that the part does not return to its original position, but when it is resumed it takes the full length of the tween (5 seconds) to complete.
This is the key difference TweenBase:Pause() and TweenBase:Cancel().
local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Position = Vector3.new(0, 10, 0)
part.Anchored = true
part.Parent = workspace
local goal = {}
goal.Position = Vector3.new(0, 50, 0)
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
task.wait(2.5)
tween:Cancel()
local playTick = tick()
tween:Play()
tween.Completed:Wait()
local timeTaken = tick() - playTick
print("Tween took " .. tostring(timeTaken) .. " secs to complete")
-- The tween will take 5 seconds to complete as the tween variables have been reset by tween:Cancel()
Pause
트위 플레이를 중지합니다. 진행 변수를 초기화하지 않으므로 TweenBase:Play() 를 호출하면 트위 플레이가 중지된 때부터 재생됩니다.
트위 진행 변수를 초기화하려면 TweenBase:Cancel() 을 사용하십시오.
Class.TweenBase.PlaybackState|PlaybackState 의 Enum. PlaybackState.Playing 에 있는 트위너만 일시 중지할 수 있습니다
반환
코드 샘플
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()
Play
트위니의 재생을 시작합니다. 재생이 이미 시작된 경우, Play() 을 호출하면 트위니가 완료되거나 중지(TweenBase:Cancel() 또는 TweenBase:Pause() 되지 않습니다.
여러 명의 십대는 동일한 개체에서 동시에 재생될 수 있지만, 동일한 속성을 애니메이션하지 않아야 합니다. 두 명의 십대가 동일한 속성을 수정하려고 시도하면 초기 트윈이 취소되고 가장 최근의 트윈에 덮어씁니다(예시 참조).
반환
코드 샘플
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 a demonstration of tween conflict. A part is instanced in the Workspace, and two tweens are created that attempt to move the part in conflicting directions.
When both tweens are played, the first tween is cancelled and overwritten by the second tween. This can be seen as the part moves along the Y axis as opposed to the Z axis.
To further demonstrate this, connections have been made for both tweens to the Tween.Completed event. Upon playing the tweens, the following is printed.
tween1: Enum.PlaybackState.Cancelled tween2: Enum.PlaybackState.Completed
These prints show that the first tween was cancelled (firing the Completed event) immediately upon the second tween being played. The second tween then went on to play until completion.
local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Position = Vector3.new(0, 10, 0)
part.Anchored = true
part.Parent = game.Workspace
local tweenInfo = TweenInfo.new(5)
-- create two conflicting tweens (both trying to animate part.Position)
local tween1 = TweenService:Create(part, tweenInfo, { Position = Vector3.new(0, 10, 20) })
local tween2 = TweenService:Create(part, tweenInfo, { Position = Vector3.new(0, 30, 0) })
-- listen for their completion status
tween1.Completed:Connect(function(playbackState)
print("tween1: " .. tostring(playbackState))
end)
tween2.Completed:Connect(function(playbackState)
print("tween2: " .. tostring(playbackState))
end)
-- try to play them both
tween1:Play()
tween2:Play()
이벤트
Completed
트위닝이 플레이를 완료하거나 TweenBase:Cancel() 으로 중지되면 화재됩니다.
패스 트위너의 Enum.PlaybackState를 연결된 함수에 전달하여 트위너가 끝난 이유를 나타내는 표시를 제공합니다. TweenBase:Pause()를 호출하면 Completed 이벤트가 실행되지 않습니다.
매개 변수
완료 시의 Enum.PlaybackState 트윈.
코드 샘플
In this example the walkspeed of any player joining the game will be slowed to 0 over 10 seconds using a Tween. The Completed event is used to reset the walkspeed after the Tween has finished playing.
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local SLOW_DURATION = 10
local function slowCharacter(humanoid)
local goal = {}
goal.WalkSpeed = 0
local tweenInfo = TweenInfo.new(SLOW_DURATION)
local tweenSpeed = TweenService:Create(humanoid, tweenInfo, goal)
tweenSpeed:Play()
return tweenSpeed
end
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
local initialSpeed = humanoid.WalkSpeed
local tweenSpeed = slowCharacter(humanoid)
tweenSpeed.Completed:Wait()
humanoid.WalkSpeed = initialSpeed
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)
This code sample includes a demonstration of tween conflict. A part is instanced in the Workspace, and two tweens are created that attempt to move the part in conflicting directions.
When both tweens are played, the first tween is cancelled and overwritten by the second tween. This can be seen as the part moves along the Y axis as opposed to the Z axis.
To further demonstrate this, connections have been made for both tweens to the Tween.Completed event. Upon playing the tweens, the following is printed.
tween1: Enum.PlaybackState.Cancelled tween2: Enum.PlaybackState.Completed
These prints show that the first tween was cancelled (firing the Completed event) immediately upon the second tween being played. The second tween then went on to play until completion.
local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Position = Vector3.new(0, 10, 0)
part.Anchored = true
part.Parent = game.Workspace
local tweenInfo = TweenInfo.new(5)
-- create two conflicting tweens (both trying to animate part.Position)
local tween1 = TweenService:Create(part, tweenInfo, { Position = Vector3.new(0, 10, 20) })
local tween2 = TweenService:Create(part, tweenInfo, { Position = Vector3.new(0, 30, 0) })
-- listen for their completion status
tween1.Completed:Connect(function(playbackState)
print("tween1: " .. tostring(playbackState))
end)
tween2.Completed:Connect(function(playbackState)
print("tween2: " .. tostring(playbackState))
end)
-- try to play them both
tween1:Play()
tween2:Play()
This code sample includes an example of how Tween.Completed can be used to determine if a Tween has been successfully completed, or cancelled.
In this case a part is instanced and tweened towards 0, 0, 0. Once the tween has completed, if the final PlaybackState is Completed then the part will explode. Were the tween to be cancelled prior to completion, the explosion would not be created.
This method can be used to link tweens to other effects, or even chain several tweens to play after each other.
local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Position = Vector3.new(0, 50, 0)
part.Anchored = true
part.Parent = workspace
local goal = {}
goal.Position = Vector3.new(0, 0, 0)
local tweenInfo = TweenInfo.new(3)
local tween = TweenService:Create(part, tweenInfo, goal)
local function onTweenCompleted(playbackState)
if playbackState == Enum.PlaybackState.Completed then
local explosion = Instance.new("Explosion")
explosion.Position = part.Position
explosion.Parent = workspace
part:Destroy()
task.delay(2, function()
if explosion then
explosion:Destroy()
end
end)
end
end
tween.Completed:Connect(onTweenCompleted)
tween:Play()