animation.pause()

Type Function
Return value none
Revision Release 2024.3703
Keywords animation, tween, timeline, interpolation, pause
See also Animation — Tweens and Timelines (guide)
animation.resume()
Tween
Timeline

Overview

The animation.pause() function pauses the following, depending on the passed parameter:

Important

Calls to this method which target specific child tweens within a Timeline are ignored. Timeline tweens are controlled/owned by the parent timeline, so you should pause the timeline itself via this method or object:pause().

Syntax

animation.pause()
animation.pause( tweenObject )
animation.pause( displayObject )
animation.pause( tagName )
animation.pause( timelineObject )
tweenObject (optional)

Tween. The specific Tween to pause.

displayObject (optional)

DisplayObject. The display object upon which all associated tweens will be paused.

tagName (optional)

String. The tag name; all tweens/timelines with this tag will be paused.

timelineObject (optional)

Timeline. The specific Timeline to pause.

Examples

All Tweens/Timelines
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()
Specific Tween
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 )
Display Object Tweens
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 )
Tagged Tweens
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" )
Timeline
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 )