I use proxy to change collections between menu and game, but when menu loads, it doesn’t acquiring input focus. Here’s the code:
Proxy.script
local MSG_LOADGAME = hash("load_game")
local MSG_LOADMENU = hash("load_menu")
local MSG_PROXYLOADED = hash("proxy_loaded")
--local MSG_PROXYUNLOADED = hash("proxy_unloaded")
function loadProxy(self,id)
if self.current_proxy then
msg.post(self.current_proxy, "final")
msg.post(self.current_proxy, "unload")
self.current_proxy = nil
end
msg.post(id, "load")
end
function init(self)
self.current_proxy = nil
msg.post("#", "load_menu")
end
function on_message(self, message_id, message, sender)
if message_id == MSG_LOADGAME then
loadProxy(self, "#GameProxy")
elseif message_id == MSG_LOADMENU then
loadProxy(self, "#MainMenuProxy")
elseif message_id == MSG_PROXYLOADED then
self.current_proxy = sender
msg.post(sender, "enable")
--msg.post(sender, "init")
end
end
MainMenu.gui_script:
local utils = require "modules.utilities"
local TOUCH = hash("touch")
-- function createWorld(self,name)
-- local x_size = window.get_size()
-- local worldNodePos = gui.get_position(self.items[#self.items])
-- worldNodePos.y = worldNodePos.y + gui.get_size(self.items[#self.items]).y
--
-- local worldNode = gui.new_box_node(worldNodePos, vmath.vector3(x_size,100,0))
-- local worldName = gui.new_text_node(vmath.vector3(0,0,0), name)
-- local lastJoin = gui.new_text_node(vmath.vector3(0,-80,0), os.date())
--
-- --Changing color
-- gui.set_color(worldNode, RgbaToVec4(203, 188, 74, 255))
-- --Changing size
-- gui.set_size(worldName, vmath.vector3(200,100,0))
-- gui.set_size(lastJoin, vmath.vector3(200,50,0))
-- --Setting parent
-- gui.set_parent(worldNode, gui.get_node("Worlds"), false)
-- gui.set_parent(worldName, worldNode, false)
-- gui.set_parent(lastJoin, worldNode, false)
-- --Setting pivot
-- gui.set_pivot(worldNode, gui.PIVOT_NW)
-- gui.set_pivot(worldName, gui.PIVOT_NW)
-- gui.set_pivot(lastJoin, gui.PIVOT_NW)
-- --Setting scale for 'lastJoin'
-- gui.set_scale(lastJoin, vmath.vector3(0.6,0.6,1))
-- end
function init(self)
msg.post(".", "acquire_input_focus")
local title = gui.get_node("Title")
gui.animate(title, "rotation", vmath.vector3(0,0,5), gui.EASING_INSINE, 4, 0, nil, gui.PLAYBACK_LOOP_PINGPONG)
-- self.items = {gui.get_node("CreateWorld")}
end
function update(self,dt)
local x_size,y_size = window.get_size()
gui.set_size(gui.get_node("Background"), vmath.vector3(x_size,y_size,0))
gui.set_size(gui.get_node("Worlds"), vmath.vector3(x_size,y_size,0))
end
function on_input(self, action_id, action)
if action_id == TOUCH and action.released then
local backToMenu = gui.get_node("BackToMenu")
local worlds_btn = gui.get_node("Play")
local exit_btn = gui.get_node("Exit")
if gui.pick_node(worlds_btn, action.x, action.y) then
msg.post("proxy:/controller", "load_game")
-- local worlds = gui.get_node("Worlds")
--
-- gui.animate(worlds, hash("position.x"), 0, go.EASING_INSINE, 0.5)
-- gui.animate(backToMenu, hash("position.y"), 650, go.EASING_INSINE, 0.5)
elseif gui.pick_node(backToMenu, action.x, action.y) then
local worlds = gui.get_node("Worlds")
gui.animate(backToMenu, hash("position.y"), 835, go.EASING_INSINE, 0.5)
gui.animate(worlds, hash("position.x"), 1400, go.EASING_INSINE, 0.5)
elseif gui.pick_node(exit_btn, action.x, action.y) then
sys.exit(0)
end
end
end