我将 Lua 与 Gideros 一起使用,并在按下后退按钮时显示警报框。根据 Gideros 文档,当按下第一个按钮时,它返回索引 1,但它似乎并没有真正以这种方式工作。我测试了应用程序我的android手机。我意识到oncomplete函数根本没有被调用,因为我尝试使用打印语句,甚至它没有被执行,所以知道为什么没有被调用吗?
local function onKeyDown(event)
if event.keyCode == KeyCode.BACK then
local alertDialog = AlertDialog.new("Confirmation", "Are you sure you want to exit?", "Cancel", "Yes")
alertDialog:show()
stage:addEventListener(Event.COMPLETE, oncomplete)
end
end
function oncomplete(e)
if e.buttonIndex == 1 then
stage:addEventListener(Event.APPLICATION_SUSPEND, suspend)
application: exit()
end
end
function suspend()
application: exit()
end
-- key events are dispatched to all Sprite instances on the scene tree (similar to mouse and touch events)
stage:addEventListener(Event.KEY_DOWN, onKeyDown)