类型 函数 返回值 无 修订 版本 2024.3703 关键词 动画, 补间动画, 时间轴, 插值, setPosition 另请参阅 动画 — 补间动画和时间轴 (指南) 补间动画 时间轴
animation.setPosition()
方法将根据传入的参数移动/设置播放位置。
将忽略对 时间轴 内特定子补间动画调用此方法。时间轴补间动画由父时间轴控制/拥有,因此您应该通过此方法或 object:setPosition() 设置时间轴本身的位置。
animation.setPosition( position ) animation.setPosition( tweenObject, position ) animation.setPosition( displayObject, position ) animation.setPosition( tagName, position ) animation.setPosition( timelineObject, position )
显示对象。 要在其上移动/设置所有补间动画位置的显示对象。
字符串。 标签名称;所有具有此标签的补间动画/时间轴都将受到影响。
local object1 = display.newRect( 50, 50, 100, 100 ) local object2 = display.newRect( 50, 150, 100, 100 ) local tween1 = animation.to( object1, { y=300 }, { time=4000 } ) local tween2 = animation.to( object2, { y=400 }, { time=2000 } ) -- Set the position of all tweens to 1 second in animation.setPosition( 1000 )
local object1 = display.newRect( 50, 50, 100, 100 ) local object2 = display.newRect( 50, 150, 100, 100 ) local tween1 = animation.to( object1, { y=300 }, { time=4000 } ) local tween2 = animation.to( object2, { y=400 }, { time=2000 } ) -- Set the position of a specific tween animation.setPosition( tween1, 1000 )
local object1 = display.newRect( 50, 50, 100, 100 ) local tween1 = animation.to( object1, { y=300 }, { time=4000 } ) local tween2 = animation.to( object1, { rotation=90 }, { time=2000, delay=2000 } ) -- Set the position of all tweens on the object animation.setPosition( object1, 3000 )
local object1 = display.newRect( 50, 50, 100, 100 ) local object2 = display.newRect( 50, 150, 100, 100 ) local tween1 = animation.to( object1, { y=300 }, { time=4000, tag="tweenTag" } ) local tween2 = animation.to( object2, { y=400 }, { time=2000, tag="tweenTag" } ) -- Set the position of all tweens with the tag "tweenTag" animation.setPosition( "tweenTag", 1000 )
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, set the timeline position to a specific time animation.setPosition( newTimeline, 2000 )
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_2000", time=2000 } } } local newTimeline = animation.newTimeline( timelineParams ) -- Set the timeline playing newTimeline:resume() -- Sometime later, set the timeline position to a specific time marker animation.setPosition( newTimeline, "marker_2000" )