• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Custom draw event when using an order table

B

Beggar Studios

Guest
Hey guys,

I'm creating an rpg in Game Maker Studio 2 and instead of using y = -y for depth I'm using an order table system where every y coordinate has a ds_list assigned to it with every instance associated with that y coordinate stored in it. The order table manager than loops through all these lists and draws the associated sprites in order to create the illusion of depth.

Now, this works perfectly if I just need to draw the sprite assigned to the instance, but now I have an object with a custom draw event where a bunch of dots and lines are drawn. I need this draw event to be excecuted in the order table manager object or else these dots and lines will not have the right depth, how can I do that?

To summarize: how do I excecute a custom draw event within another object so my order table system still works?
 
B

Beggar Studios

Guest
Just tested it and it worked! Just had to do this in the order table script:

Code:
// render everything in the Order Table (could clip to viewport here)
for(var index=0;index<global.ot_size;index++)
{
    // get the list of instances for this "Y" index
    var l = global.ot[# 0,index];
    
    // IF there is anything in the list, draw it
    var count = ds_list_size(l)-1;
    if( count>=0 )
    {
        while(count>=0)
        {
            // Get the instance in the list
            var i = ds_list_find_value(l,count--);
            
            if(i.sprite_index != -1){
                draw_sprite_ext( i.sprite_index, i.image_index,i.x,i.y, i.image_xscale, i.image_yscale, 0, c_white, i.image_alpha);
            }
            
            //Run custom draw events
            with(i){
                draw = true;
                event_perform(ev_draw, 0)
                draw = false;
            }
        }
    }
}
and then do this in the object draw event:

Code:
if(draw){
    if(obj_soul_chest.image_index == 1){
        for(i=y; i>y-200;i--){
            draw_sprite(spr_pixel, 0, (x+4)+sin(1/2*i),i);
            draw_sprite(spr_pixel, 0, (x-4)+sin(1/2*i),i);
        }
    }
} else {
    scr_OT_add(id);
}
 
Top