Composer - navigating correctly between scenes

I have an app with a linear like structure of the scenes.

Splash -> SceneA <-> SceneB <-> SceneC

What is the correct way of navigating between these scenes? As far as I’ve understood I have 3 options:

1)

In SceneA call composer.gotoScene(“SceneB”, sceneTrans)

To return from SceneB call composer.gotoScene(“SceneA”, sceneTrans)

2)

In SceneA call composer.showOverlay(“SceneB”, sceneTrans)

To return from SceneB call composer.hideOverlay(“SceneB”, sceneTrans)

(can I do the second call within SceneB???)

3)

In SceneA call composer.showOverlay(“SceneB”, sceneTrans)

To return from SceneB call composer.hideOverlay(sceneTrans)

I have tried 1) and it has worked until recently (calling the gotoScene(parent) in the Android return button handler doesn’t seem to work).

Since my scenes are strictly hierarchical, should I instead use the overlay options?

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.

Rob

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:

The ok button (I’m using widget candy):

\_G.GUI.NewButton( { name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= "OptionsOKButton", x &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = "center", y &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = "bottom", width &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = "35%", theme &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = \_G.theme, caption &nbsp; &nbsp; &nbsp; &nbsp; = "OK", textAlign &nbsp; &nbsp; &nbsp; = "center", icon &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 0, onRelease &nbsp; &nbsp; &nbsp; = function() composer.gotoScene("app", composer.state.sceneTransition) end, scale = GUIScale, parentGroup = masterGroup, } )

The HW back button:

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.

Rob

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:

The ok button (I’m using widget candy):

\_G.GUI.NewButton( { name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= "OptionsOKButton", x &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = "center", y &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = "bottom", width &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = "35%", theme &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = \_G.theme, caption &nbsp; &nbsp; &nbsp; &nbsp; = "OK", textAlign &nbsp; &nbsp; &nbsp; = "center", icon &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 0, onRelease &nbsp; &nbsp; &nbsp; = function() composer.gotoScene("app", composer.state.sceneTransition) end, scale = GUIScale, parentGroup = masterGroup, } )

The HW back button:

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).