object:getPosition()

Type Function
Return value Number
Revision Release 2024.3703
Keywords animation, timeline, interpolation, getPosition
See also object:setPosition()
animation.setPosition()
Timeline
animation.*

Overview

The object:getPosition() method returns the position of the Timeline in milliseconds.

Note

This value may be greater than the duration of the timeline, essentially indicating that all child tweens have completed. If necessary, the returned value can be constrained to a range between 0 and the timeline's duration by passing true to the method call — see below for details.

Syntax

object:getPosition( [getClipped] )
getClipped (optional)

Boolean. If true, the returned value will be between 0 and the timeline duration. Default is false.

Example

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 )