object:setPosition()

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

概述

移动/设置使用 animation.newTimeline() 创建的 时间轴 的播放位置。

语法

object:setPosition( 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()
标记位置
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()