如何在 Corona 中使用 "back" 硬件按钮?
How to use "back" hardware button in Corona?
我想在触摸底部面板上的后退按钮("home"、"menu")时触发暂停菜单场景,但我不知道该怎么做。这可以在 Corona SDK 中实现吗?
您将 key
事件的侦听器添加到应响应关键事件的场景中的运行时。这是返回键必备;没有它,系统将退出(即退出)应用程序。假设一个 scene
对象,你可以这样做:
function scene:key(event)
if ( event.keyName == "back" ) then
-- handle the back key press however you choose
end
end
Runtime:addEventListener( "key", scene )
有关 key
事件的详细信息,请参阅 the Corona documentation。
至于“暂停菜单场景”,你可能想用一个overlay。来自 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.
我想在触摸底部面板上的后退按钮("home"、"menu")时触发暂停菜单场景,但我不知道该怎么做。这可以在 Corona SDK 中实现吗?
您将 key
事件的侦听器添加到应响应关键事件的场景中的运行时。这是返回键必备;没有它,系统将退出(即退出)应用程序。假设一个 scene
对象,你可以这样做:
function scene:key(event)
if ( event.keyName == "back" ) then
-- handle the back key press however you choose
end
end
Runtime:addEventListener( "key", scene )
有关 key
事件的详细信息,请参阅 the Corona documentation。
至于“暂停菜单场景”,你可能想用一个overlay。来自 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.