animation.pause()

类型 函数
返回值
修订 版本 2024.3703
关键词 动画, 补间动画, 时间线, 插值, 暂停
另请参阅 动画 — 补间动画和时间线 (指南)
animation.resume()
补间动画
时间线

概述

animation.pause() 函数会根据传入的参数暂停以下内容:

重要

调用此方法以暂停时间线中特定子补间动画的请求将被忽略。时间线补间动画由父时间线控制/拥有,因此您应该通过此方法或object:pause()暂停时间线本身。

语法

animation.pause()
animation.pause( tweenObject )
animation.pause( displayObject )
animation.pause( tagName )
animation.pause( timelineObject )
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=400 } )
local tween2 = animation.to( object2, { y=400 }, { time=200 } )

-- Sometime later, pause all tweens and timelines
animation.pause()
特定补间动画
local object1 = display.newRect( 50, 50, 100, 100 )
local object2 = display.newRect( 50, 150, 100, 100 )

local tween1 = animation.to( object1, { y=300 }, { time=400 } )
local tween2 = animation.to( object2, { y=400 }, { time=200 } )

-- Sometime later, pause a specific tween
animation.pause( tween1 )
显示对象补间动画
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 } )

-- Sometime later, pause all tweens on the object
animation.pause( object1 )
带标签的补间动画
local object1 = display.newRect( 50, 50, 100, 100 )
local object2 = display.newRect( 50, 150, 100, 100 )

local tween1 = animation.to( object1, { y=300 }, { time=400, tag="tweenTag" } )
local tween2 = animation.to( object2, { y=400 }, { time=200, tag="tweenTag" } )

-- Sometime later, pause all tweens with the tag "tweenTag"
animation.pause( "tweenTag" )
时间线
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, pause the timeline
animation.pause( newTimeline )