transition.cancel still firing onComplete

I just noticed a bug in a game I’m working on, I’m calling transition.cancel() on exiting the scene to cancel all transitions but if I time it correctly I can get the occasional onComplete event firing after the cancel call.  I saw a few bug reports about this on the forums but nothing about it being addressed, anybody?

Are you using Storyboard or Composer?

If you’re using Composer, then you should cancel things in the “will” phase.  For Storyboard, you may need to set up the “willExitScene” event to remove things before the scene transitions away.

Rob

Cheers Rob.  Using storyboard.  I didn’t realise there was a willExitScene event (I’m calling it at the start if exitScene), I’ll give it a go.

OK willExitScene looks to be for reloading of scenes actually my post isn’t clear, for reloading I’m actually going game scene > loading scene > game scene so technically I am exiting the scene completely, destroying it, then loading it.

What I’m not getting is if I call transition.cancel() why do they not all just get killed right away?

OK so I migrated everything over to composer and called transition.cancel in the “will” phase.  Its just the same?  Really puzzled by this one.  

What I’d really love to know from someone at Corona is, is there a possibility the onComplete function be called after transition.cancel is called or not?  If I know this I can go bug hunting or adjust the code accordingly??

Hi.  I think transitions are working just fine.  You’ve probably got a logic or code error.  

I separated out an example to demonstrate this is working:

local function testIt( msg, transitionTime, delTime ) local obj = display.newCircle( 100, 100, 10 ) obj.msg = msg obj.onComplete = function( self ) print( self.msg ) end transition.to( obj, { x = 300, time = transitionTime, onComplete = obj } ) obj.timer = function(self) transition.cancel( self ) display.remove(self) end timer.performWithDelay( delTime, obj ) end

Try this:

testIt( "test 1 - delete and cancel after complete.", 1000, 1500 )

Now try this:

testIt( "test 2 - delete and cancel before complete.", 1000, 750 )

With Storyboard, there are two exiting a scene events:  willExitScene() is used for things that you need to do before the scene leaves the screen.  exitScene() happens after the scene has left the screen.  You should do things in willExitScene() that need to stop before the scene leaves, perhaps stopping music, pausing physics, canceling timers, stopping Runtime events.  These things can change the screen in the middle of the transition before exitScene() triggers.

Rob

@roaminggamer Yeah I think you’re right.  If I leave the scene looping on a timer with a random delay gameScene>loadingScene>gameScene then I get no errors, its once I bring the buttons/touch listeners into play that it starts to misbehave.  This may take some time to find…  :o

Are you using Storyboard or Composer?

If you’re using Composer, then you should cancel things in the “will” phase.  For Storyboard, you may need to set up the “willExitScene” event to remove things before the scene transitions away.

Rob

Cheers Rob.  Using storyboard.  I didn’t realise there was a willExitScene event (I’m calling it at the start if exitScene), I’ll give it a go.

OK willExitScene looks to be for reloading of scenes actually my post isn’t clear, for reloading I’m actually going game scene > loading scene > game scene so technically I am exiting the scene completely, destroying it, then loading it.

What I’m not getting is if I call transition.cancel() why do they not all just get killed right away?

OK so I migrated everything over to composer and called transition.cancel in the “will” phase.  Its just the same?  Really puzzled by this one.  

What I’d really love to know from someone at Corona is, is there a possibility the onComplete function be called after transition.cancel is called or not?  If I know this I can go bug hunting or adjust the code accordingly??

Hi.  I think transitions are working just fine.  You’ve probably got a logic or code error.  

I separated out an example to demonstrate this is working:

local function testIt( msg, transitionTime, delTime ) local obj = display.newCircle( 100, 100, 10 ) obj.msg = msg obj.onComplete = function( self ) print( self.msg ) end transition.to( obj, { x = 300, time = transitionTime, onComplete = obj } ) obj.timer = function(self) transition.cancel( self ) display.remove(self) end timer.performWithDelay( delTime, obj ) end

Try this:

testIt( "test 1 - delete and cancel after complete.", 1000, 1500 )

Now try this:

testIt( "test 2 - delete and cancel before complete.", 1000, 750 )

With Storyboard, there are two exiting a scene events:  willExitScene() is used for things that you need to do before the scene leaves the screen.  exitScene() happens after the scene has left the screen.  You should do things in willExitScene() that need to stop before the scene leaves, perhaps stopping music, pausing physics, canceling timers, stopping Runtime events.  These things can change the screen in the middle of the transition before exitScene() triggers.

Rob

@roaminggamer Yeah I think you’re right.  If I leave the scene looping on a timer with a random delay gameScene>loadingScene>gameScene then I get no errors, its once I bring the buttons/touch listeners into play that it starts to misbehave.  This may take some time to find…  :o