In my app, I want multiple uses for the back button, but each time I run only the first one works.
Here is an example of my code from two of the rules screens.
The first:
[lua]
local function onKeyEvent( event )
local phase = event.phase
local keyName = event.keyName
if ( “back” == keyName ) then
director:changeScene(“home”,“fade”)
return true
end
return false
end
Runtime:addEventListener( “key”, onKeyEvent )[/lua]
Then I have this code in another spot:
[lua]
local function onKeyEvent( event )
local phase = event.phase
local keyName = event.keyName
if ( “back” == keyName ) then
director:changeScene(“rules1”,“fade”)
return true
end
return false
end
–add the key callback
Runtime:addEventListener( “key”, onKeyEvent )[/lua]
When I run this on the device, it only uses the first overide. On every screen it returns to the home scene.
I have seen the storyboard examples of creating a memory, but I also have other back button functions in the actual game as well, so that approach will not work.