Hi all,
So I have this weird finding when trying to make a RETRY option on a scene.
I have a scene named ‘scene1’ which has a retry button during a game pause, calls ‘retryLevel.lua’ which in turn calls back ‘scene1’.
This is how I coded it initially (yes, using composer).
-- in scene1.lua local function onPauseRetry() -- called when Retry button is pressed local thisScene = composer.getSceneName ("current") local options = { params = { level = thisScene } } composer.removeScene ( thisScene ) composer.gotoScene ("retryLevel", options ) end
--- in retryLevel.lua function scene:create( event ) local level = event.params.level composer:gotoScene (level, "fade", 50) end
It seems to work. HOWEVER, on the second run of ‘scene1’, there are all sorts of weird errors and behaviour , especially in the game physics where everything seems to have doubled (eg. forces, tweening speed, density, etc.) which make me think that ‘scene1’ wasn’t totally cleaned up! These properties seem to triple on the third retry, and so on until the scene just crashes!
So I revised ‘retry.lua’ to allow a small delay before calling back ‘scene1’ like so…
-- in retryLevel.lua function scene:create( event ) local thisScene = composer.getSceneName ("current") local level = event.params.level composer:removeScene ( thisScene ) local function retry() composer:gotoScene (level, "fade", 50) end local t = timer.performWithDelay( 150, retry, 1 ) end
…and presto!! I can retry ‘scene1’ as many times as I want with all those weirdness gone!
So to my finding and question: Corona needs some time to cleanup a scene before calling it back, Yes? Secondly, is this the right way to do a ‘Retry’ option of a scene? If there is anything better, would you guys recommend the method?
Thanks,
Santi
). Thanks for reminding me of such a handy tool.