Back and Menu buttons sample code is missing. I’m using Windows version of Corona for Android and the KeyEvents folder does not exist in the Hardware folder. Am I missing something? Or an I missing something?
I was excited and wanted to try the new feature but I cannot “See new sample Hardware/KeyEvents/main.lua”.
Glenn [import]uid: 38820 topic_id: 12404 reply_id: 312404[/import]
I have little problem with director. When i press back button, director changes scene, but in new scene graphics are messed up. Few images are completely white. Here is my code:
local function onKeyEvent(event)
if event.keyName == "back" then
Runtime:removeEventListener("key",onKeyEvent)
director:changeScene ("menu")
return true
end
end
Runtime:addEventListener("key",onKeyEvent)
Could someone help me little bit? [import]uid: 18445 topic_id: 12404 reply_id: 45227[/import]
I tried the code you posted above and on my Galaxy S the event.phase are wrong. When I push the menu or back button it says up. Then when I release the button it says down.
There’s also a problem with the back key. If I press and hold the back key down for more than a second the phase will get stuck and not change (menu button does not have this problem).
[import]uid: 38820 topic_id: 12404 reply_id: 45238[/import]
I have problem with back key and director. Mentioned above. Could someone post working example how to use back key and director?
Using Acer Liquid, Android 2.3.4 [import]uid: 18445 topic_id: 12404 reply_id: 45276[/import]
Has somebody back key working with director? When i press back key, director changes scene, but some graphics are completely white. Help, please. [import]uid: 18445 topic_id: 12404 reply_id: 45389[/import]
uapo15 I had the same problem but got it working. You cannot call a scene within the back key listener. Instead I set a flag and handle it in a enterframe.
local backButtonPushed = false
local function animate(event)
if backButtonPushed == true then
if fxVolumeOn == true then audio.play(clickSound) end
director:changeScene("levelselect1")
end
end
local function onKeyEvent( event )
local phase = event.phase
local keyName = event.keyName
if phase == "up" and keyName == "back" then
backButtonPushed = true
end
return true
end
I got new problem: glennbjr code works, but it is someway global.
When i first time press back key in “about” scene, director changes back to “menu” scene. Thats ok, but after that, in every other scene director changes to “menu” scene. And that happens even in scene where i dont have that glennbjr back key code.
I have removed listeners in every time director changes scene. And now i cant close my game in main menu with pressing back key. I can only quit my game pressing home key, but then my game is still running in background.
I am little bit confused. Could someone help me?
[import]uid: 18445 topic_id: 12404 reply_id: 45406[/import]
Sounds like an error somewhere in your code. I’m able to switch between all my scenes without any problems.
To exit my game from the main menu I handle the back button, drop down a menu with “Exit Game?” with yes or no buttons, if yes is pushed then exit game with os.exit().
I’m using an older version of Director with its cleanup function. Director Beta 1.3 or earlier should work with the code below. Here’s a complete scene of how the back button can be handled in a director scene. I hope the code is not too long for this post :o|
[code]module(…, package.seeall)
– GROUPS
local localGroup = display.newGroup()
– BACK BUTTON FLAG
local backButtonPushed = false
– LISTENERS
local function animate(event)
if backButtonPushed == true then
backButtonPushed = false
os.exit()
– or
–director:changeScene(“menu”)
end
end
local function onKeyEvent( event )
local phase = event.phase
local keyName = event.keyName
if phase == “up” and (keyName == “back”) then
backButtonPushed = true
end
Thanks for you time. I created new project based on your code above and it worked perfectly. So i have error somewhere in my code. Going to recreate my game based to code above. Hope that it will start working after that. [import]uid: 18445 topic_id: 12404 reply_id: 45436[/import]
Got it working now! I dont know why it didnt work before, but now it just works. Big thanks for your time glennbjr! [import]uid: 18445 topic_id: 12404 reply_id: 45443[/import]