• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Clicking top object – default behavior in GMS2 with manual depth?

MartinK12

Member
When u want to click top object and did not set depth of those objects the top object will not be clicked but actually the clicked object will be the first one placed in the room. But when you set depth each of those objects manually the object with the lowest depth will always be clicked.

I need to know is this the default behavior in GMS2, so no other solutions (except setting depth manually) for clicking top objects are necessary? Thank You

If u need more explanation I made simple project and below is a screenshot of what I’m talking about:
GMS2 top click.jpg
Same project. Top image = squares depth set automatically by GMS2 (all squares have depth = 0, why?). Bottom image = squares depth set in each object manually by me from 4 to 1.

for top clicked obj_click has this basic code in step event:
Code:
if mouse_check_button_pressed(mb_left) {
    mouse_clear(mb_left);
    ins_top_clicked = instance_position(mouse_x, mouse_y, all);
   
    if (ins_top_clicked != noone) {
        with (all) clicked = false;
        ins_top_clicked.clicked = true;      
    }
    else with (all) clicked = false;
}
each colorful object has basic code in step event:
Code:
if clicked image_index = 1; // with yellow outline
else image_index = 0; // without outline
 
Last edited:
Top