object:getPosition()

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

概述

object:getPosition() 方法返回时间轴的位置,单位为毫秒。

注意

此值可能大于时间轴的持续时间,这实际上表明所有子补间动画都已完成。如有必要,可以通过向方法调用传递 true 来将返回值限制在 0 到时间轴持续时间之间的范围内 — 详情请参见下文。

语法

object:getPosition( [getClipped] )
getClipped (可选)

布尔值 如果为 true,则返回值将介于 0 和时间轴持续时间之间。默认为 false

示例

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

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

-- Set the timeline playing
newTimeline:resume()

-- Sometime later, pause the timeline
newTimeline:pause()

-- Check the timeline position
local currentPosition = newTimeline:getPosition()
print( currentPosition )