Type Function Return value none Revision Release 2025.3721 Keywords animation, tween, timeline, interpolation, cancel See also Animation — Tweens and Timelines (guide) Tween Timeline
The animation.cancel() function will cancel the following, depending on the passed parameter:
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 cancel the timeline itself via this method or object:cancel().
animation.cancel() animation.cancel( tweenObject ) animation.cancel( displayObject ) animation.cancel( tagName ) animation.cancel( timelineObject )
DisplayObject. The display object upon which all associated tweens will be cancelled.
String. The tag name; all tweens with this tag will be cancelled.
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, cancel all tweens and timelines
animation.cancel()
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, cancel a specific tween
animation.cancel( 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, cancel all tweens on the object
animation.cancel( 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, cancel all tweens with the tag "tweenTag"
animation.cancel( "tweenTag" )