Change Proxy Menu/Level (SOLVED)

This is my “main” structure

and this is my code to load/unload “scenes”

function init(self)
	self.current_proxy = "menu#menu"
	msg.post(self.current_proxy, "load")
end

function on_message(self, message_id, message, sender)
    if message_id == hash("proxy_loaded") then
        -- New world is loaded. Init and enable it.
        msg.post(sender, "init")
        msg.post(sender, "enable")
        msg.post(sender, "acquire_input_focus")
        print("proxy_loaded", sender)
    elseif message_id == hash("pause_game") then
    	msg.post(self.current_proxy, "set_time_step", {factor = 0, mode = 1})
    elseif message_id == hash("change_proxy") then
    	msg.post(self.current_proxy,"unload")
    	
    	if message.proxy == "" then
			print("reset proxy")
		else    	
    		self.current_proxy = message.proxy
    	end
    elseif message_id == hash("proxy_unloaded") then
		print("proxy_unloaded", sender)
		msg.post(sender, "release_input_focus")
		msg.post(self.current_proxy, "load")
    end
end

to change the scene or reset the level I send a message:
example for Menu button in level complete:

msg.post("main:/levels#level_controler", "change_proxy", {proxy = "menu#menu"})
  1. I am using the correct method?
  2. for reset the level I unload and load the same proxy
  3. how can make a fade transition? maybe with gameobject and go.animate the alpha? I need a sprite size of 1280x720.

Sorry for my english.

Yes, that looks about right.

Sounds good. Unless the collection contains a huge amount of assets that need to be loaded it should be very fast to unload and load it.

There are multiple ways to create transitions. @Mathias_Westerdahl made a post about screen transitions using stencil buffers here: Screen fade using stencil buffers

A quick and dirty solution would be to add a fullscreen/stretched sprite and animate it’s alpha value:

-- start by setting alpha to 0
go.set("#sprite", "tint.w", 0)
-- animate alpha once from it's current value of 0 to the value of 1.0 over a period of 1.5 seconds
go.animate("#sprite", "tint.w", go.PLAYBACK_ONCE_FORWARD, 1.0, go.EASING_LINEAR, 1.5, 0)
1 Like

thanks britzl, one quesiton more, for transition I test with gameobject and z position 1.0 all is ok but the problem is when I have a gui element, maybe I need use gui object and streched box for transition?

In the default render script the gui is drawn in a separate pass, and a sprite would in that case be drawn below the gui. You could as you have concluded yourself instead use a gui with a stretched box node and animate that using

gui.set_color(node, vmath.vector4(1,1,1,0))
gui.animate(node, gui.PROP_COLOR, vmath.vector4(1,1,1,1), gui.EASING_LINEAR, 1.5, 0)

Perfect, I have some gui element front my gui transition fade, how can set my transition gui on top?

A gui will always be drawn on top of sprites, particle effects and so on. And if you have multiple gui scenes you can control their order using gui.set_render_order().

1 Like

great, the fade transition is working great.