Cancel all transitions in group

Hi!

I’m new to Corona and Lua, but I am definitely loving it so far.

The biggest hurdle for me seems to be handling different screens. Specifically, how to properly clean everything when switching. I’ve figured out timers and objects in general, but what do i do when it comes to transitions?

My game creates a bunch of objects and animates them on the x-axis using a transition. On the completion it calls a RemoveMe-function, to remove itself. Whenever I change screen, I get runtime errors because the objects have already been removed by changing screen. So the pest solution would be to cancel ALL transitions before removing the objects.

So, in short: is there a quick way to cancel all transitions in the current group? Otherwise, how would I go on about coding a simple “cancellAllTransitions”-function for doing this myself – maybe storing transitions in an array and using a for loop to remove them all?

I am using the director class, but I though this question was more general and posted it here.

Thanks,
Mark [import]uid: 13935 topic_id: 5288 reply_id: 305288[/import]

you’ve got the right idea. store all your transitions, then loop through and call .cancel()

remember to check the transition hasn’t finished already though. if it has you’ll want to remove it from the array so you don’t try cancelling a nil object. remove it in a generic oncomplete event

you can probably do something like this (untested though)

[lua]local transitions = {}
local ref

function onTransitionComplete(obj)
– obj is ball etc, so obj.ref is ball.ref
transitions[obj.ref]=nil
obj.ref=nil
end

– make a transition
ref = transition.to(ball, {time=1000, x=100, onComplete=onTransitionComplete})
– store a reference to itself in the object being moved
– so oncomplete can reference it
ball.ref=ref
– store reference to ball in transitions table,
– using the transition ref as the key
transitions[ref] = ball
– make another
ref = transition.to(ball2, {time=1000, x=50, onComplete=onTransitionComplete})
– store a reference to itself
ball2.ref=ref
transitions[ref]=ball2

function killTransitions()
for i, v in pairs(transitions) do
transition.cancel(i)
transitions[i]=nil
end
end

killTransitions()[/lua] [import]uid: 6645 topic_id: 5288 reply_id: 17720[/import]