主题
TweenInfo
概览
| 字段 | 值 |
|---|---|
| Kind | Data · 数据 Data |
| Realm | common |
TweenInfo 用来描述一次补间动画的时间与节奏配置,集中承载持续时间、缓动风格、缓动方向、重复次数、是否反向播放以及延迟时间这六项信息。它本身不驱动任何动画,而是作为配置载体被补间相关接口读取,由这些接口据此决定数值推进的快慢与往复方式。
适用场景
需要让某个属性在一段时间内平滑过渡时,先构造一个 TweenInfo 说明节奏,再把它交给 TweenService:Create 生成补间实例并播放;也可以用它检查某个缓动风格与方向组合是否符合预期。
使用要点
通过 TweenInfo.New(duration, easingStyle, easingDirection, repeatCount, reverses, delayTime) 或等价的 TweenInfo(...) 简写构造,再传给 TweenService:Create。easingStyle 与 easingDirection 必须使用命名枚举成员。
注意事项
TweenInfo 是动画配置对象,支持 TweenInfo.New(...) 与 TweenInfo(...) 两种等价构造。示例代码必须自包含:所有变量必须声明后使用,禁止引用未声明的 tween/animation 等变量。
代码示例
构造 TweenInfo 动画配置并回读参数
lua
-- @runtime client
-- 构造完整参数的 TweenInfo:2 秒时长、Bounce 缓动、InOut 方向、重复 3 次、往返播放、延迟 0.5 秒开始
local tweenInfo = TweenInfo.New(
2.0, -- Duration:单次动画时长(秒)
Enums.EasingStyle.Bounce, -- EasingStyle:缓动曲线类型
Enums.EasingDirection.InOut, -- EasingDirection:缓动方向
3, -- RepeatCount:重复次数
true, -- Reverses:是否往返播放
0.5 -- DelayTime:开始前的延迟时间(秒)
)
-- 再用简写形式构造第二个配置,仅传入必要参数,其余使用默认值
local simpleTweenInfo = TweenInfo(1.0, Enums.EasingStyle.Linear, Enums.EasingDirection.Out)
-- 回读属性验证构造结果:完整配置应保留 Bounce 与往返播放标记
print("完整配置时长:", tweenInfo.Duration)
print("缓动曲线是否为 Bounce:", tweenInfo.EasingStyle == Enums.EasingStyle.Bounce)
print("是否往返播放:", tweenInfo.Reverses)
print("延迟时间:", tweenInfo.DelayTime)
-- 对比两份配置的时长差,用于决定两段动画的节奏差异
print("简写配置默认重复次数:", simpleTweenInfo.RepeatCount)
print("两份配置时长差:", tweenInfo.Duration - simpleTweenInfo.Duration)属性 (6)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
Duration | Float | 1.0 | 补间动画的持续时间,单位为秒。 |
EasingStyle | EasingStyle | Enums.EasingStyle.Linear | TweenInfo 的缓动风格属性,类型为 EasingStyle 枚举,用于指定补间动画在时间轴上的变化曲线,例如线性、二次、弹跳等表现。 |
EasingDirection | EasingDirection | Enums.EasingDirection.Out | 补间动画的缓动方向,决定缓动函数的作用阶段。 |
RepeatCount | Int | 0 | 补间动画的重复次数。0 表示播放一次,-1 表示无限循环。 |
Reverses | Bool | false | 是否在每次重复时反向播放补间动画。 |
DelayTime | Float | 0 | 补间动画开始前的延迟时间,单位为秒。 |
关联类型
函数 (1)
New
签名:New(duration: Float, easingStyle?: EasingStyle, easingDirection?: EasingDirection, repeatCount?: Int, reverses?: Bool, delayTime?: Float) -> TweenInfo (TweenInfo 对象)
创建一个 TweenInfo 对象,用于描述补间动画的时间参数,包括持续时间、缓动风格、缓动方向、重复次数、是否往返以及延迟时间。除持续时间外,其余参数均为可选。
| 参数 | 类型 | 说明 |
|---|---|---|
duration | Float | 持续时间 |
easingStyle? | EasingStyle | 缓动风格,使用 Enums.EasingStyle 的命名成员。 |
easingDirection? | EasingDirection | 缓动方向,使用 Enums.EasingDirection 的命名成员。 |
repeatCount? | Int | 重复次数, 默认 0 (0=一次, -1=无限) |
reverses? | Bool | 反向播放, 默认 false |
delayTime? | Float | 延迟时间, 默认 0 |
示例代码
构造 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)))