Skip to content

TweenInfo

概览

字段
KindData · 数据 Data
Realmcommon

TweenInfo 是补间动画的配置对象,用于定义动画的持续时间、缓动风格、重复次数等参数。它通过 TweenService 创建补间时传入,控制动画的播放行为。

适用场景

在需要平滑过渡界面元素或三维物体的位置、大小、透明度等属性时,使用 TweenInfo 配置动画效果,例如制作按钮点击缩放或角色移动动画。

使用要点

通过 TweenInfo.New(duration, easingStyle, easingDirection, repeatCount, reverses, delayTime) 或等价的 TweenInfo(...) 简写构造,再传给 TweenService:Create。easingStyle 与 easingDirection 必须使用命名枚举成员。

注意事项

TweenInfo 是动画配置对象,支持 TweenInfo.New(...) 与 TweenInfo(...) 两种等价构造。示例代码必须自包含:所有变量必须声明后使用,禁止引用未声明的 tween/animation 等变量。

代码示例

构造 TweenInfo 并读取属性

lua
-- @runtime client
-- 使用 TweenInfo.New 构造动画配置对象,并读取各属性值
local duration = 2.0  -- 动画时长(秒)
local easingStyle = Enums.EasingStyle.Bounce  -- 缓动风格
local easingDirection = Enums.EasingDirection.InOut  -- 缓动方向
local repeatCount = 3  -- 重复次数
local reverses = true  -- 是否反向播放
local delayTime = 0.5  -- 延迟时间(秒)

local info = TweenInfo.New(duration, easingStyle, easingDirection, repeatCount, reverses, delayTime)

-- 读取并打印各属性值
print("Duration:", info.Duration)
print("EasingStyle:", info.EasingStyle)
print("EasingDirection:", info.EasingDirection)
print("RepeatCount:", info.RepeatCount)
print("Reverses:", info.Reverses)
print("DelayTime:", info.DelayTime)

属性 (6)

Name类型默认值说明
DurationFloat1.0补间动画的持续时间,单位为秒。
EasingStyleEasingStyleEnums.EasingStyle.Linear补间动画的缓动风格,决定动画的速度曲线。
EasingDirectionEasingDirectionEnums.EasingDirection.Out补间动画的缓动方向,决定缓动函数的作用阶段。
RepeatCountInt0补间动画的重复次数。0 表示播放一次,-1 表示无限循环。
ReversesBoolfalse是否在每次重复时反向播放补间动画。
DelayTimeFloat0补间动画开始前的延迟时间,单位为秒。

关联类型

函数 (1)

New

签名:New(duration: Float, easingStyle?: EasingStyle, easingDirection?: EasingDirection, repeatCount?: Int, reverses?: Bool, delayTime?: Float) -> TweenInfo (TweenInfo 对象)

创建一个新的 TweenInfo 对象,用于定义补间动画的播放参数。

参数类型说明
durationFloat持续时间
easingStyle?EasingStyle缓动风格,使用 Enums.EasingStyle 的命名成员。
easingDirection?EasingDirection缓动方向,使用 Enums.EasingDirection 的命名成员。
repeatCount?Int重复次数, 默认 0 (0=一次, -1=无限)
reverses?Bool反向播放, 默认 false
delayTime?Float延迟时间, 默认 0

返回值 TweenInfo (TweenInfo 对象)

示例代码

构造 TweenInfo

lua
-- @runtime client
local info = TweenInfo.New(
    0.5,                         -- 持续时间(秒)
    Enums.EasingStyle.Quad,      -- 缓动风格
    Enums.EasingDirection.InOut  -- 缓动方向
)
print(string.format('时长=%.2f 风格=%s 方向=%s',
    info.Duration, tostring(info.EasingStyle), tostring(info.EasingDirection)))