Reputation: 39
I want to cause a pause-menu scene when I touch back button located on the bottom panel (with "home", "menu") but I don't understand how to do it. This can be implemented in Corona SDK?
Upvotes: 1
Views: 1067
Reputation: 1183
You add a listener for key
events to the Runtime in the scenes that should respond to key events. This is essential for the back key; without it, the system will back out of (i.e. exit) the app. Assuming a scene
object, you could do:
function scene:key(event)
if ( event.keyName == "back" ) then
-- handle the back key press however you choose
end
end
Runtime:addEventListener( "key", scene )
For more information about key
events, see the Corona documentation.
As for the “pause menu scene”, you probably want to use an overlay. From the documentation on composer.showOverlay()
:
This function loads an overlay scene above the currently active scene (the parent scene), leaving the parent scene intact. When an overlay is shown, an overlay-specific scene event parameter, event.parent, will be dispatched to the overlay scene.
This parameter provides you with a reference to the parent scene object so that you may call functions/methods within it.
Upvotes: 3