I have also a problem implementing a back button. I have the code like I used on Android:
local function onKeyEvent( event ) local phase = event.phase local keyName = event.keyName if ( "back" == keyName and phase == "up" ) then local currentScene = storyboard.getCurrentSceneName() if currentScene == "menu" then native.requestExit() elseif currentScene == "gameplay" then if not storyboard.state.isPaused and not storyboard.state.isExit then storyboard.state.pauseGame() elseif storyboard.state.isPaused then storyboard.state.resumeGame() else storyboard.state.goToMap() end elseif currentScene == "map" then storyboard.state.goToMenuFromMap() elseif currentScene == "info" then storyboard.state.goToMenuFromInfo() elseif currentScene == "trashStore" then storyboard.state.goToMenuFromStore() end return true end end Runtime:addEventListener( "key", onKeyEvent )
Hitting the back button always hard terminates the game, so it starts from the splash screen when the game icon is tapped again. Even if I just write
native.requestExit()
in the onKeyEvent handler - it always hard exits.
Is there any special syntax for implementing a back key handler on WP8?
o.