Depth Priority Issue

cjcrack

Member
Hello, i'm having a major issue and i'll try my best to explain it.

Say object 1 has a depth of 1 and object 2 has a depth of 0, so when overlapping, object 2 would be on top.

when I click with my mouse on the area they are overlapping, I only want the actions of the top object to occur, or the object with the lowest depth (in this case object 2)

In other words, when i click on overlapping objects, i ONLY want the lowest depth object to be "clicked" instead of having all the objects under the mouse being "clicked"

http://imgur.com/5JTvet8

So if i click in that overlapping red box region in this picture, i only want the actions of the top object to work (blue suit)

I'm guessing there is some type of depth priority code I can use for this when clicking the mouse. I know very very little code, all my games are like 95% drag and drop so if this does require some complicated code, a clear example of it would be greatly appreciated!
 
G

guadalcanal

Guest
Try giving all the clickable objects the same parent object. Then in a "global mouse pressed" event, use a loop to cycle through all objects with that parent that are overlapping the mouse position and find the object with the lowest depth. If you don't know how to do that I can expound.
 

cjcrack

Member
Try giving all the clickable objects the same parent object. Then in a "global mouse pressed" event, use a loop to cycle through all objects with that parent that are overlapping the mouse position and find the object with the lowest depth. If you don't know how to do that I can expound.
yes, please expand further. I understand global mouse and parent objects, but you lost me after that. If this includes code, i have no idea how to go about it, please help
 

TheouAegis

Member
Create Event:
clicked = false;
doClick = false;

Mouse Left Button Released Event:
clicked = true;

Draw Event:
if clicked
{
with obj_Button clicked = false;
doClick = true;
}

Step:
if doClick
{
doClick = false;
//run whatever code you need to
}


Alternatively, just run all the code in the draw event instead of setting doClick to true, but most of the time you shouldn't. Make sure all your clickable objects are parented to obj_Button or whatever you want to call it.
 
G

guadalcanal

Guest
yes, please expand further. I understand global mouse and parent objects, but you lost me after that. If this includes code, i have no idea how to go about it, please help
In your global mouse pressed event do something like this
Code:
var lowest_depth = 9999999;
var obj_clicked = -1;
with(parent_obj){
     if(depth<=lowest_depth){
          lowest_depth = depth;
          obj_clicked = id;
     }
}
if(obj_clicked){
      show_message("You clicked on "+string(id));
}
 
Top