TweenBase

非推奨を表示

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。

作成できません
閲覧できません

中間のインターポレーションハンドラーの抽象ベースクラス; Tween の親クラス。

概要

プロパティ

  • 読み取り専用
    複製されていません
    並列読み取り

    Tween アニメーションの現在の状態を表示する読み取り専用プロパティ。

方法

  • Cancel():()

    再生を停止し、tween 変数をリセットします。その後、TweenBase:Play() を呼び出すと、ティーンのプロパティが目的地にインターポレートしますが、そのためにはアニメーションの全長を取ります。

  • Pause():()

    tween の再生を停止します。進行変数をリセットしないため、TweenBase:Play() を呼択すると、ティーンは一時停止した瞬間から再生を再開します。

  • Play():()

    tween の再生を開始します。再生がすでに開始されている場合、Play() を呼び出すと、tweenが終了したか停止した場合を除き、効果はありません(TweenBase:Cancel() または TweenBase:Pause() によって)。

プロパティ

PlaybackState

読み取り専用
複製されていません
並列読み取り

Tween アニメーションの現在のステージを表示する読み取り専用プロパティ。各状態の説明は、Enum.PlaybackState を参照してください。Tween:Play() のような関数を使用して変更。

コードサンプル

Tween PlaybackState

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 によって変更されるプロパティではなく、のみ減少変数をリセットします。アニメーションの途中で減少をキャンセルしても、プロパティは元の値にリセットされません。一度再開すると、昼休みの全期間がアニメーションを完了するために必要になるため、TweenBase:Pause() と異なります。


戻り値

()

コードサンプル

ティーンのキャンセル

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

()

tween の再生を停止します。進行変数をリセットしないため、TweenBase:Play() を呼択すると、ティーンは一時停止した瞬間から再生を再開します。

tween の進行変数をリセットしたい場合は、TweenBase:Cancel() を使用します。

停止できるのは、PlaybackStateEnum. PlaybackState.Playing にいるティーンのみで、他の状態のティーンは停止しません。ティーンが異なる (例: の結果として、0より大きい) である場合、ティーンを一時停止する試みは失敗し、ティーンは指定された遅延時間後に再生します。


戻り値

()

コードサンプル

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()

Play

()

tween の再生を開始します。再生がすでに開始されている場合、Play() を呼び出すと、tweenが終了したか停止した場合を除き、効果はありません(TweenBase:Cancel() または TweenBase:Pause() によって)。

複数のティーンが同時に同じオブジェクトで再生できますが、同じプロパティをアニメートしてはなりません。2人のティーンが同じプロパティを変更しようとすると、最初のティーンはキャンセルされ、最新のティーンに上書きされます(例を参照)。


戻り値

()

コードサンプル

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()
Tween Conflict

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

tween が再生を終えたり、TweenBase:Cancel() で停止したときに発火します。

パス Enum.PlaybackState ティーンの のを接続された機能に渡して、ティーンが終了した理由の示唆を与えます。呼び出し TweenBase:Pause() は、Completed イベントを発動させません。

パラメータ

playbackState: Enum.PlaybackState

完了時の tween の Enum.PlaybackState


コードサンプル

Tween Completed

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)
Tween Conflict

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()
Verifying a Tween has Completed

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()