How to make GUI appear on the background?

I noticed that GUI always appear on the front.
I need a GUI that appear in the back of sprites.

How to do that?

  1. Copy the default render script from “builtins/render/default.render_script” and put it in your project.

  2. Change project settings to use the new script (see “bootstrap/render” in settings)

  3. Reorder the drawing in the update() function in the script so you draw GUI first (Check out http://www.defold.com/doc/rendering for more info on rendering):

     function update(self)
       render.set_depth_mask(true)
       render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color, [render.BUFFER_DEPTH_BIT] = 1, [render.BUFFER_STENCIL_BIT] = 0})
    
       render.set_depth_mask(false)
       render.set_viewport(0, 0, render.get_window_width(), render.get_window_height())
       render.disable_state(render.STATE_DEPTH_TEST)
       render.enable_state(render.STATE_BLEND)
       render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA)
       render.disable_state(render.STATE_CULL_FACE)
    
       -- Set up for view and projection for drawing (GUI, text)
       render.set_view(vmath.matrix4())
       render.set_projection(vmath.matrix4_orthographic(0, render.get_window_width(), 0, render.get_window_height(), -1, 1))
    
       render.enable_state(render.STATE_STENCIL_TEST)
       -- Draw
       render.draw(self.gui_pred)
       render.draw(self.text_pred)
       render.disable_state(render.STATE_STENCIL_TEST)
    
       -- Set up for view and projection for drawing (sprites, particles etc)
       render.set_view(self.view)
       render.set_projection(vmath.matrix4_orthographic(0, render.get_width(), 0, render.get_height(), -1, 1))
       -- Draw
       render.draw(self.tile_pred)
       render.draw(self.particle_pred)
       render.draw_debug3d()
    
       render.set_depth_mask(false)
       render.draw_debug2d()
     end
3 Likes