Updated timer and transition libraries

Just a heads up.

I’ve recently updated the timer and transition libraries.

The updates added support for tags to timers. This means that when you create a timer, you can pass a new optional tag parameter that you can later use to control the all timers that share the same tag with.

Another new feature is three new function calls for both timer and transition: timer.pauseAll(), timer.resumeAll() and timer.cancelAll(). These are self-explanatory, i.e. they control all timers and/or transitions with one function call.

The final new feature is a new property for the transition library. By default, if you pass nil or no argument to transition function calls, e.g. transition.cancel(), then it will affect all transitions. This sometimes leads to issues where the developer passes a reference to a display object to the function after said display object has already been removed. This is the same as passing nil to the function, so instead of controlling that one display object, all transitions will accidentally be paused/resumed/cancelled.

By setting transition.ignoreEmptyReference = true, all nil and empty arguments will be simply ignored instead. After setting this, you may still control all transitions via the three new functions.


To use these new features, you need to download Solar2D 2020.3611 or a newer version.

10 Likes

What is the difference between transition.pause() and transition.pauseAll()?

p.s: transition.pause() called with no parameters

Hi @SUPER_TOKI,

I think there is only one difference. Property .ignoreEmptyReference affect only transition.pause().

See ignoreEmptyReference for more information.

Have a nice day:)
ldurniat

It’s like @ldurniat said:

Essentially, if you don’t set transition.ignoreEmptyReference = true, then transition.pause() and transition.pauseAll() essentially do the same thing.

However, as I’ve often read on these forums, people are frequently controlling all transitions by accident when they try to do something like transition.pause( myObject ), but myObject has already been removed, which means that it is nil.

By using transition.pauseAll(), there is no chance for accidentally controlling all running transitions.

local obj = display.newRect(100, 100, 100, 100)

transition.to(obj, {time=1000, onComplete=function()
print(“onComplete”)
end })

display.remove(obj)
obj = nil

I interpreted that in the above situation, if obj is nil, onComplete also cancels execution.

If ignoreEmptyReference is set to true
It means that if I don’t change all of the previous transition.cancel() to cancelAll() the problem will occur.

p.s: Anyway, I think this is a meaningful update for users who don’t handle exceptions. :smiley:

Yeah, it’s essentially just:

local object = {}
for i = 1, 5 do
    object[i] = display.newRect( 50, 50+60*i, 50, 50 )
    transition.to( object[i], { time=500, x=object[i].x+300 } )
end

display.remove(object[1])
object[1] = nil
transition.pause(object[1]) -- Since object[1] is nil, all transitions are paused.

But with the new update, you can do:

transition.ignoreEmptyReference = true

local object = {}
for i = 1, 5 do
    object[i] = display.newRect( 50, 50+60*i, 50, 50 )
    transition.to( object[i], { time=500, x=object[i].x+300 } )
end

display.remove(object[1])
object[1] = nil
transition.pause(object[1]) -- nothing happens, other transitions carry on.

It’s just one less thing to worry about when using pauseAll/resumeAll/cancelAll. Plus it makes the transition and timer libraries behave in a more similar way, which is a plus.

1 Like