object:getDuration()

类型 函数
返回值 数字
修订版本 版本 2024.3703
关键词 动画, 时间轴, 插值, getDuration
另请参阅 时间轴
animation.*

概述

object:getDuration() 方法返回时间轴的持续时间(以毫秒为单位)。

注意
  • 此值将受时间轴的速度比例影响。

  • 如果是无限循环的时间轴(子补间无限迭代),此值为 nil,因为实际上没有预先确定的持续时间。

语法

object:getDuration()

示例

local object1 = display.newRect( 50, 50, 100, 100 )

-- Create a timeline object
local timelineParams = {
    tweens = {
        { startTime=1000, tween={ object1, { x=400 }, { time=4000, iterations=5 } } },
        { startTime=2000, tween={ object1, { y=400 }, { time=4000, easing=easing.outQuad } } }
    },
    delay = 1000
}
local newTimeline = animation.newTimeline( timelineParams )

-- Set the timeline playing
newTimeline:resume()

-- Get the timeline's playing duration
local duration = newTimeline:getDuration()
print( duration )  --> 21000