# Change Proxy Menu/Level (SOLVED)

**URL:** <https://forum.defold.com/t/change-proxy-menu-level-solved/9022>\
**Category:** Questions\
**Created:** [June 7, 2017, 11:40pm UTC](https://forum.defold.com/t/change-proxy-menu-level-solved/9022 "2017-06-07T23:40:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![qkygames](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/q/6de8d8/32.png) [@qkygames](https://forum.defold.com/u/qkygames)\
**Post date:** [June 7, 2017, 11:40pm UTC](https://forum.defold.com/t/change-proxy-menu-level-solved/9022/1 "2017-06-07T23:40:39Z")

</div>

This is my “main” structure

 ![](https://forum-defold-uploads.b-cdn.net/original/2X/5/54c12392b735dfe5d1c970302837b3b1810ec974.png)

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

```lua
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:

```lua
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.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [June 8, 2017, 4:13am UTC](https://forum.defold.com/t/change-proxy-menu-level-solved/9022/2 "2017-06-08T04:13:08Z")

</div>

> [@qkygames](#):
>
> 1. I am using the correct method?

Yes, that looks about right.

> [@qkygames](#):
>
> 1. for reset the level I unload and load the same proxy

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.

> [@qkygames](#):
>
> 1. how can make a fade transition? maybe with gameobject and go.animate the alpha? I need a sprite size of 1280x720.

There are multiple ways to create transitions. @Mathias_Westerdahl made a post about screen transitions using stencil buffers here: [Screen fade using stencil buffers](https://forum.defold.com/t/screen-fade-using-stencil-buffers/2678)

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)

```

---

<div class="post-metadata">

**Author:** ![qkygames](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/q/6de8d8/32.png) [@qkygames](https://forum.defold.com/u/qkygames)\
**Post date:** [June 8, 2017, 11:42am UTC](https://forum.defold.com/t/change-proxy-menu-level-solved/9022/3 "2017-06-08T11:42:19Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [June 8, 2017, 12:00pm UTC](https://forum.defold.com/t/change-proxy-menu-level-solved/9022/4 "2017-06-08T12:00:52Z")

</div>

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)

```

---

<div class="post-metadata">

**Author:** ![qkygames](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/q/6de8d8/32.png) [@qkygames](https://forum.defold.com/u/qkygames)\
**Post date:** [June 8, 2017, 3:10pm UTC](https://forum.defold.com/t/change-proxy-menu-level-solved/9022/5 "2017-06-08T15:10:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [June 8, 2017, 3:19pm UTC](https://forum.defold.com/t/change-proxy-menu-level-solved/9022/6 "2017-06-08T15:19:09Z")

</div>

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().

---

<div class="post-metadata">

**Author:** ![qkygames](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/q/6de8d8/32.png) [@qkygames](https://forum.defold.com/u/qkygames)\
**Post date:** [June 8, 2017, 3:30pm UTC](https://forum.defold.com/t/change-proxy-menu-level-solved/9022/7 "2017-06-08T15:30:14Z")

</div>

great, the fade transition is working great.
