Skip to content

TweenInfo ​

TweenInfo 用来描述一次补间动画的时间与节奏配置,集中承载持续时间、缓动风格、缓动方向、重复次数、是否反向播放以及延迟时间这六项信息。它本身不驱动任何动画,而是作为配置载体被补间相关接口读取,由这些接口据此决定数值推进的快慢与往复方...

概览 ​

TweenInfo 用来描述一次补间动画的时间与节奏配置,集中承载持续时间、缓动风格、缓动方向、重复次数、是否反向播放以及延迟时间这六项信息。它本身不驱动任何动画,而是作为配置载体被补间相关接口读取,由这些接口据此决定数值推进的快慢与往复方式。

可通过 TweenInfo.New(duration, easingStyle, easingDirection, repeatCount, reverses, delayTime) 构造

代码示例 ​

构造 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)

属性 ​

名称类型默认值说明
DurationFloat1.0补间动画的持续时间,单位为秒。
EasingStyleEasingStyleEnums.EasingStyle.LinearTweenInfo 的缓动风格属性,类型为 EasingStyle 枚举,用于指定补间动画在时间轴上的变化曲线,例如线性、二次、弹跳等表现。
EasingDirectionEasingDirectionEnums.EasingDirection.Out补间动画的缓动方向,决定缓动函数的作用阶段。
RepeatCountInt0补间动画的重复次数。0 表示播放一次,-1 表示无限循环。
ReversesBoolfalse是否在每次重复时反向播放补间动画。
DelayTimeFloat0补间动画开始前的延迟时间,单位为秒。