object:setPosition()

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

Overview

Moves/sets the playback position of a Timeline created with animation.newTimeline().

Syntax

object:setPosition( position )
position (required)

Number or String. The position (time or marker) to move/set the playback to, as follows:

  • A number indicating the time to move the playback to, in milliseconds.
  • The string name of a time marker associated with the timeline.

Examples

Time Position
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 position
newTimeline:setPosition( 2000 )

-- Set the timeline playing
newTimeline:resume()
Marker Position
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 } } }
    },
    markers = {
        { name="marker_start", time=0 },
        { name="marker_2000", time=2000 },
        { name="marker_3000", time=3000 }
    }
}
local newTimeline = animation.newTimeline( timelineParams )

-- Set the timeline position
newTimeline:setPosition( "marker_2000" )

-- Set the timeline playing
newTimeline:resume()