Some of this might help @Prawn:
Input
Each game object that want to receive input must acquire input by posting a message to itself:
msg.post(".", "acquire_input_focus")
You should also understand how input is propagated when you work with collections and collection proxies. Read up on this here:
http://www.defold.com/doc/input#anchor-iacp
"Screen management"
So, in a game where you wish to have a number of screens/menus then one way to achieve this is to put each screen/menu in it’s own GUI file. Each GUI file points to a GUI script file with the logic for that GUI. All of this is described in detail in the documentation on the GUI component:
http://www.defold.com/doc/gui
Now, one way to manage these different GUIs is to have a game object with a controller script that takes care of showing and hiding GUIs depending on the state of your game. You can post messages to this controller script to show different GUIs and let the controller script in turn post to the different GUIs of your game to show/hide them. An example:
controller.script:
local function hide_screen(url)
if url then
msg.post(url, "hide")
end
end
-- show a screen and hide the previously shown screen if one existed
local function show_screen(self, url, message)
hide_screen(self.current_screen)
self.current_screen = url
msg.post(self.current_screen, "show", message or {})
end
-- start by hiding all guis and show the main menu
function init(self)
hide_screen("main_menu")
hide_screen("level_menu")
show_screen(self, "main_menu")
end
function on_message(self, message_id, message, sender)
if message_id == hash("show_main_menu") then
show_screen(self, msg.url("main_menu"))
elseif message_id == hash("show_level_menu") then
-- pass along additional data such as which level to play to the level menu
show_screen(self, msg.url("level_menu"), message)
end
end
main_menu.gui_script:
function final(self)
msg.post(".", "release_input_focus")
end
function on_message(self, message_id, message, sender)
if message_id == hash("show") then
msg.post(".", "enable")
msg.post(".", "acquire_input_focus")
elseif message_id == hash("hide") then
msg.post(".", "disable")
msg.post(".", "release_input_focus")
end
end
function on_input(self, action_id, action)
if action.released and gui.pick_node(gui.get_node("play_level"), action.x, action.y) then
msg.post("controller", "show_level_menu", { level_id = 1234 })
end
end