When an object have a transition during he is removed, the transition continue :
I always build a delete function to my object to manage the project, because the finalize event is not called at the good time.
local r=display.newRect(0,0,100,100) r.delete=function() if r then if r.tr then transition.cancel(r.tr) ; r.tr=nil end r:removeSelf() // error here because r.removeSelf is nil, so no function can be called r=nil end end r.tr=transition.to(r,{time=10000,x=200,onComplete=r.delete}) timer.performWithDelay(5000,function() r:removeSelf() end)
Because of the excecution delay during a frame, I prefere delete the object immediately during the calculus process, not in the end of the frame.
local tableOfObjects = {} local r=display.newRect(0,0,100,100) ; tableOfObjects[r]=r // this reference in tableOfObjects will be managed too r.enterFrame=function() end //all my actions r.tr=transition.to(r,{time=2000,x=200,onComplete=r.delete}) // I use delete function at the end just to try if no bug arrived r:addEventListener( "anEvent", r ) // touch, collision, etc... Runtime:addEventListener("enterFrame",r) //I remove properly the actions here r.manageDelete=function() tableOfObjects[r]=nil if r.tr then transition.cancel( r.tr ) ; r.tr=nil end r:removeEventListener( "finalize", r ) r:removeEventListener( "anEvent", r ) Runtime:removeEventListener( "enterFrame", r ) end //this function delete the object immediately r.delete=function(fromFinalize) if not r.isDeleted then r.manageDelete() r.isDeleted=true if not fromFinalize then r:removeSelf() end // if I call the delete function with the removeSelf method, I don't removed twice end end function r:finalize(event) r.delete(true) r=nil end r:addEventListener( "finalize", r ) timer.performWithDelay(1000,function() r:removeSelf() end)
That’s look " a lot " but it is better like this : manage all the cancellation and removeEvent in one side, and then remove the object.