Dear Corona,
I am using the storyboard api to figure out which scene is currently displayed like this:
local currentSceneName = storyboard.getCurrentSceneName() swl.printInfo("The current scene is: " .. currentSceneName, fileName, methodName) local currentScene = storyboard.getScene(currentSceneName)
However, if an overlay is displayed using storyboard.showOverlay(…), the above code will still return the original scene. For example:
-
Load a scene, menu.lua
-
From menu.lua scene show an myOverlay overlay
-
Push the hardware back button
-
The code in main.lua to get the current scene will still retrieve the menu scene not the myOverlay scene. How can I retrieve the the current scene including overlays?
main.lua
local storyboard = require "storyboard" -- setup hardware back key listener local function onKeyEvent( event ) -- Handle back key if (event.keyName == "back") and (event.phase == "up") and (system.getInfo("platformName") == "Android") then local currentSceneName = storyboard.getCurrentSceneName() local currentScene = storyboard.getScene(currentSceneName) if currentScene ~= nil then -- Each scene is coded with its own function for handling the back button, including overlays. if (currentScene.onBackKey and type(currentScene.onBackKey)=="function") then return currentScene:onBackKey(event) else return true end else return false end end -- Return false to indicate that this app is \*not\* overriding the received key. -- This lets the operating system execute its default handling of this key. return false end Runtime:addEventListener( "key", onKeyEvent ) storyboard.goToScene("menu")
menu.lua
... -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) storyboard.showOverlay( "myOverlay", { time = 250, effect = "fromTop", isModal = true } ) end function scene:onBackKey(event) -- handle the back key on this scene ... return true end ...
myOverlay.lua
... function scene:onBackKey(event) -- handle the back key on this scene, which happens to be an overlay ... return true end ...
Thanks!