类型 函数 返回值 无 修订版 发行版 2024.3703 关键词 动画,补间,时间轴,插值,setSpeedScale 另请参见 动画 — 补间和时间轴 (指南) 补间 时间轴
animation.setSpeedScale()
方法将设置播放速度比例,具体取决于传入的参数
在 时间轴 内对特定子补间调用此方法会被忽略。时间轴补间由父时间轴控制/拥有,因此你应通过此方法或 object:setSpeedScale() 设置时间轴本身的速度比例。
更改速度比例不会影响开始播放所设定的任何延迟。换句话说,只有受影响对象实际播放的部分将通过此调用进行修改。
animation.setSpeedScale( scale ) animation.setSpeedScale( tweenObject, scale ) animation.setSpeedScale( displayObject, scale ) animation.setSpeedScale( tagName, scale ) animation.setSpeedScale( timelineObject, scale )
数字。相对速度比例。这必须是一个大于 0
的正数。默认情况下,速度比例为 1
(正常速度)。大于 1
的值将增加速度,而低于 1
的值将减小速度。
显示对象。要在其上设置所有补间速度比例的显示对象。
字符串。标记名称;带有此标记的所有补间/时间轴都将受到影响。
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 speed scale of all tweens and timelines animation.setSpeedScale( 2.5 )
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 speed scale of a specific tween animation.setSpeedScale( tween1, 2.5 )
local object1 = display.newRect( 50, 50, 100, 100 ) local tween1 = animation.to( object1, { y=300 }, { time=2000 } ) local tween2 = animation.to( object1, { rotation=90 }, { time=1000, delay=1000 } ) -- Set the speed scale of all tweens on the object animation.setSpeedScale( object1, 2.5 )
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 speed scale of all tweens with the tag "tweenTag" animation.setSpeedScale( "tweenTag", 2.5 )
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() -- Set the speed scale of the timeline animation.setSpeedScale( newTimeline, 2.5 )