Last active
May 25, 2020 12:45
-
-
Save szilardhuber/038972e6bc4881d882df7e8d5e9627d2 to your computer and use it in GitHub Desktop.
Defold - menu and loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local score = 0 | |
local function load_menu(score_in) | |
msg.post("loader#mainmenu", "load") | |
if not (score_in == nil) then | |
score = score_in | |
end | |
end | |
local function unload_menu() | |
msg.post("loader#mainmenu", "unload") | |
end | |
local function load_game() | |
msg.post("loader#level", "load") | |
end | |
local function unload_game() | |
msg.post("loader#level", "unload") | |
end | |
function init(self) | |
msg.post(".", "acquire_input_focus") | |
load_menu() | |
end | |
function on_message(self, message_id, message, sender) | |
if message_id == hash("start_game") then | |
unload_menu() | |
load_game() | |
elseif message_id == hash("game_over") then | |
unload_game() | |
load_menu(message.score) | |
elseif message_id == hash("proxy_loaded") then | |
msg.post(sender, "enable") | |
msg.post("mainmenu:/go", "score", { score = score }) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment