How to cancel all transitions and timers in Corona SDK

When using “Composer” in Corona SDK, it is absolutely important to cancel and remove all active transitions and timers before leaving the current scene. If you don’t do this, you will start getting weird errors when testing your code.

Here is how you should do it:

To cancel all transitions, use the following function:

transition.cancel()

For Timers, you will need to do it individually. First put the new timer in a variable (monsterTimer):

monsterTimer = timer.performWithDelay (1000, function () createMonster (‘small’) end,10) — Creates 10 monsters, one every second

Then, cancel it via the following two functions:

timer.cancel (monsterTimer) –Cancels the timer
monsterTimer = nil –Destroys the timer

Author: admin

Leave a Reply

Your email address will not be published.