抽象基础类为中间插件处理器;父级是 Tween 。
概要
方法
停止播放,然后重置 tween 变量。如果你 then call TweenBase:Play() , tween 变量的属性将继续交叉到目的地,但需要完整长度的动画才能完成。
停止播放 тви补间动画。不会重置其进度变量,因此如果您调用 TweenBase:Play(),斑点将从暂停的那一刻起重新播放。
开始播放一个补间动画。如果播放已经开始,调用 Play() 无效,除非特效已经完成或已停止(通过 TweenBase:Cancel() 或 TweenBase:Pause() 来)。
活动
当调整器结束播放时或当它被 TweenBase:Cancel() 停止时触发。
属性
PlaybackState
仅读取性属性,显示 Tween 动画的当前阶段。请参阅 Enum.PlaybackState 了解每个阶段的描述。使用函数 like Tween:Play() 来更改。
代码示例
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
停止播放一个 Tween ,并重置 tween 变量。
只重置 tween 变量,不是 twee补间动画 的属性被更改。如果您在�ween 的动画中途取消,属性不会重置到其原始值。与 TweenBase:Pause() 在一旦恢复后,它需要完整的 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 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(),斑点将从暂停的那一刻起重新播放。
如果您想重置 tween 的进度变量,请使用 TweenBase:Cancel() 。
您只能暂停 PlaybackState 中的青少年,而其他状态的青少年不会暂停。如果 tween 在不同的 Class.T
返回
代码示例
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() 来)。
多个십几岁的玩家可以同时在同一对象上玩,但他们不能动画同一属性。如果两个十几岁的玩家尝试修改同一属性,初始�ween 将被取消并由最新的潮流汽车覆盖 (请参阅示例)。
返回
代码示例
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()
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 。
代码示例
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)
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()
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()