2d_warrior
Member
I need to make something that will return the top most instance where the mouse cursor is currently clicking. This is probably different in Studio 2, so how would I adapt the code below? It doesn't matter if the draw order is always the same, just that I can find from multiple instances at the mouse cursor which is drawing over all others. Here is the code I used to use, but I don't know this will actually get the top most instance as they might all be on the same layer, or depth in Studio 2. How do I change this to loop, and get the top most drawn instance at the mouse xy, using something like collision point probably?
Create event:
clicked_id = -4
clicked_object = "none"
clicked_top_depth=1000000000000000
Step Event:
//Gets the id of the top most clicked object at mouse xy cords
if mouse_check_button_pressed(mb_left)
{
clicked_id = -4
clicked_object = "none"
clicked_top_depth=1000000000000000
check=0
with (all)
{
if id != other.id
{
check=0
check = collision_point(mouse_x,mouse_y,id,true,false)
if check >0
{
//chosen only if depth is lower
if check.depth<=other.clicked_top_depth
{
other.clicked_id=check
other.clicked_object=object_get_name(check.object_index)
other.clicked_top_depth=other.clicked_id.depth
}
}
}
}
}
Draw GUI Event:
draw_text(0,0,clicked_object)
draw_text(0,30,clicked_id)
Create event:
clicked_id = -4
clicked_object = "none"
clicked_top_depth=1000000000000000
Step Event:
//Gets the id of the top most clicked object at mouse xy cords
if mouse_check_button_pressed(mb_left)
{
clicked_id = -4
clicked_object = "none"
clicked_top_depth=1000000000000000
check=0
with (all)
{
if id != other.id
{
check=0
check = collision_point(mouse_x,mouse_y,id,true,false)
if check >0
{
//chosen only if depth is lower
if check.depth<=other.clicked_top_depth
{
other.clicked_id=check
other.clicked_object=object_get_name(check.object_index)
other.clicked_top_depth=other.clicked_id.depth
}
}
}
}
}
Draw GUI Event:
draw_text(0,0,clicked_object)
draw_text(0,30,clicked_id)