SOLVED event_perform(ev_gui, 0) Doesn't work in any way???

FoxyOfJungle

Kazan Games
Hello.
I'm trying to draw the items on a created layer in reverse order (inverse depth), because GMS 2 always creates objects below existing ones.


In the following video, first I do it the way it works, using the normal draw event, however if I use event_perform(ev_gui, 0) to call the GUI event of an object, it just doesn't work...

See:



Note that the instances that need to be drawn in the reverse order have visible turned off, as I wouldn't need to draw the event twice, my goal is to use event_perform() just for that. Reason: I wouldn't have to manually draw the draw event for all instances.



Code used in the video:

obj_controller: (create event)

GML:
// SETUP LAYERS
global.Layer_Index = 0;
global.Layer_Array[0] = layer_create(0, "Default Layer");


// Instances draw scripts
function layer_script_gui_objects()
{
    /// @func layer_script_gui_objects()
    if (event_type == ev_draw)
    {
        if (event_number == 0)
        {
            var u = 0;
            repeat (array_length(global.Layer_Array))
            {
                var _array = layer_get_all_elements(global.Layer_Array[u]);
   
                var i = array_length(_array)-1;
                repeat (array_length(_array))
                {
                    if (layer_get_element_type(_array[i]) == layerelementtype_instance)
                    {
                        var L = layer_instance_get_instance(_array[i])
                        with (L)
                        {
                            // Draw all UI layer instances in the Draw GUI Event (trying to do it...) in the reverse depth order:
                            //show_debug_message(object_get_name(object_index)); // for view instance name
                            event_perform(ev_gui, 0);
                        }
                    }
                    i -= 1;
                }
                u += 1;
            }
        }
    }
}

layer_script_end(global.Layer_Array[global.Layer_Index], layer_script_gui_objects);

obj_block: (draw gui event)

GML:
draw_self();
draw_set_halign(fa_center);
draw_text(x, y-48, my_layer);
draw_set_halign(fa_left);



I will make a brief explanation of what I am doing:

I'm creating a program, all there is in the room are two layers of instances, the first is with depth 0, it is used to create the main canvas, everything is drawn in the Draw GUI event. The second layer is created within the game, this layer will serve to place the instances of windows (they need to be above the canvas).

All objects in the room use the Draw GUI event (Canvas, UI, Windows...).


Only two layers in the room: Canvas (for main interface) and UI (for windows, buttons, textboxes...)


The problem (inverse depth with new instances created):


(These windows are in the UI layer)

I would be grateful if anyone can give me an idea of what it might be or how I could solve it. Thanks! :)
 
Last edited:

FoxyOfJungle

Kazan Games
Now it's perfect! šŸ˜ƒ




There was another detail as well, I should arrive if it is being drawn in Draw GUI, as it was being drawn in normal Draw:

GML:
if (event_number == ev_gui)

Final Code:

GML:
function canvas_ui_layer_script()
{
    /// @func canvas_ui_layer_script()
    if (event_type == ev_draw)
    {
        if (event_number == ev_gui)
        {
            var _array = layer_get_all_elements(layer_get_id("UI"));
         
            var i = array_length(_array)-1;
            repeat (array_length(_array))
            {
                if (layer_get_element_type(_array[i]) == layerelementtype_instance)
                {
                    var L = layer_instance_get_instance(_array[i]);
                    with (L)
                    {
                        // Draw All UI Objects
                        event_perform(ev_draw, ev_gui);
                    }
                }
                i -= 1;
            }
        }
    }
}

layer_script_end(layer_get_id("UI"), canvas_ui_layer_script);
 
Last edited:
Top