You can only have one overlay open at any one given time. It doesn’t work like a stack. It’s really a goto. If you want to implement a stack system, you have to keep track of the scenes you’ve visited in the past and when you need to back up (i.e. back button), you would need to look in your list of previously visited scenes and do a .gotoScene() on that scene to back out.
Ok, goto is what I have now. Since a child scene is always called by a specific parent, I have no need to keep track of anything (I hope). Scene B is always the child of Scene A etc. So I just use goto with a hard coded scene.
This strategy has worked perfectly - until I implemented support for the hardware back button in Android.
I have two ways of backing out of a scene: An OK button and the Android back button. As far as I can see, the exact same code is run for both cases:
local function onKeyEvent( event ) if (event.phase=="up" and event.keyName=="back") then composer.gotoScene("app", composer.state.sceneTransition) end return true end Runtime:addEventListener( "key", onKeyEvent )
Using the OK button, everything works every time.
But using the back button I get problems. If I only go from SceneA to SceneB and back it works, but if I do a SceneA -> SceneB ->SceneC ->SceneB -> SceneA it fails. The screen becomes black (note! no error msgs are logged). When I press the back button again SceneB shows momentarily before the screen is black again. It almost looks like SceneA cannot be shown.
This happens only if I have visited SceneC (it does not matter if I return from SceneC by the OK button or by the Android return button).
You can only have one overlay open at any one given time. It doesn’t work like a stack. It’s really a goto. If you want to implement a stack system, you have to keep track of the scenes you’ve visited in the past and when you need to back up (i.e. back button), you would need to look in your list of previously visited scenes and do a .gotoScene() on that scene to back out.
Ok, goto is what I have now. Since a child scene is always called by a specific parent, I have no need to keep track of anything (I hope). Scene B is always the child of Scene A etc. So I just use goto with a hard coded scene.
This strategy has worked perfectly - until I implemented support for the hardware back button in Android.
I have two ways of backing out of a scene: An OK button and the Android back button. As far as I can see, the exact same code is run for both cases:
local function onKeyEvent( event ) if (event.phase=="up" and event.keyName=="back") then composer.gotoScene("app", composer.state.sceneTransition) end return true end Runtime:addEventListener( "key", onKeyEvent )
Using the OK button, everything works every time.
But using the back button I get problems. If I only go from SceneA to SceneB and back it works, but if I do a SceneA -> SceneB ->SceneC ->SceneB -> SceneA it fails. The screen becomes black (note! no error msgs are logged). When I press the back button again SceneB shows momentarily before the screen is black again. It almost looks like SceneA cannot be shown.
This happens only if I have visited SceneC (it does not matter if I return from SceneC by the OK button or by the Android return button).