Tween

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

Tween 对象控制了插值的播放。创建和配置一个 TweenTweenService:Create() 函数完成; Instance.new() 不能用于这个特定对象。

请注意,虽然梯子配置在梯子创建后可以访问,但它不能被修改。如果需要新目标来进行插值,必须创建新的 Tween

请注意,多个青少年可以同时在同一个对象上播放,但不得互相插入相同的属性。如果两个青少年尝试修改相同的属性,初始青少年将被取消并由最新的补间动画覆盖。

代码示例

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

概要

属性

继承自TweenBase属性

方法

继承自TweenBase方法
  • Cancel():()

    停止播放并重置渐变变量。如果你然后调用 TweenBase:Play() , 青少年的属性将继续向目的地交付,但为此需要整个动画的全长。

  • Pause():()

    停止青补间动画的播放。不重置其进度变量,这意味着如果你调用 TweenBase:Play(),青少年将从暂停播放的那一刻恢复播放。

  • Play():()

    开始播放青补间动画。请注意,如果播放已经开始,调用 Play() 无效,除非青少年已经完成或被停止(通过 TweenBase:Cancel()TweenBase:Pause() )。

活动

继承自TweenBase活动

属性

Instance

只读
未复制
读取并联

这个属性的 Tween (只读) 指向被插入的 Instance 的属性。

代码示例

This code sample includes a simple function that will return true if the instance of a tween is a Part.

Tween Instance

local TweenService = game:GetService("TweenService")
local function isInstanceAPart(tween)
local instance = tween.Instance
return instance:IsA("BasePart")
end
local tweenInfo = TweenInfo.new()
local instance = Instance.new("Part")
local tween = TweenService:Create(instance, tweenInfo, {
Transparency = 1,
})
print(isInstanceAPart(tween))

TweenInfo

只读
未复制
读取并联

仅读属性,包含有关如何执行插值的 Tween 信息,使用 TweenInfo 数据输入。

代码示例

An example of the range of different interpolation effects that can be used in Tweens.

TweenInfo Examples

-- A TweenInfo with all default parameters
TweenInfo.new()
-- A TweenInfo with its time set to 0.5 seconds.
TweenInfo.new(0.5)
-- A TweenInfo with its easing style set to Back.
TweenInfo.new(0.5, Enum.EasingStyle.Back)
-- A TweenInfo with its easing direction set to In.
TweenInfo.new(0.5, Enum.EasingStyle.Back, Enum.EasingDirection.In)
-- A TweenInfo that repeats itself 4 times.
TweenInfo.new(0.5, Enum.EasingStyle.Back, Enum.EasingDirection.In, 4)
-- A TweenInfo that reverses its interpolation after reaching its goal.
TweenInfo.new(0.5, Enum.EasingStyle.Back, Enum.EasingDirection.In, 4, true)
-- A TweenInfo that loops indefinitely.
TweenInfo.new(0.5, Enum.EasingStyle.Back, Enum.EasingDirection.In, -1, true)
-- A TweenInfo with a delay of 1 second between each interpolation.
TweenInfo.new(0.5, Enum.EasingStyle.Back, Enum.EasingDirection.In, 4, true, 1)

方法

活动