animation.setSpeedScale()

类型 函数
返回值
修订版 发行版 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 )
scale (必需)

数字相对速度比例。这必须是一个大于 0 的正数。默认情况下,速度比例为 1(正常速度)。大于 1 的值将增加速度,而低于 1 的值将减小速度。

tweenObject (可选)

补间要在其上设置速度比例的特定 补间

displayObject (可选)

显示对象要在其上设置所有补间速度比例的显示对象。

tagName (可选)

字符串标记名称;带有此标记的所有补间/时间轴都将受到影响。

timelineObject (可选)

时间轴要在其上设置速度比例的特定 时间轴

示例

所有补间/时间轴
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 )