Advertisement
EvePot

Depth Checking Cursor

Feb 9th, 2025 (edited)
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // STEP EVENT
  2. // target initialized in the Create Event
  3.  
  4. //Note that I have conversions from gui layer to in-room, but as I know that is all functioning,
  5. //I omitted it from here. To simplify just assume cx and cy are the mouse position relative to
  6. //what layer it is interracting with
  7.  
  8. //ds_list creation
  9. var _list = ds_list_create();
  10.  
  11. //fill ds_list with all objects at this position
  12. var _fill = instance_position_list(cx, cy, all, _list, false);
  13.  
  14.  
  15. //If there is more than 1 object (since cursor is 1 object always seen)
  16. if (_fill > 1)
  17. {
  18.   //Loop through the list
  19.   for (var i = 0; i < _fill; ++i;)
  20.   {
  21.     if instance_exists(_list[| i]) //If the instance in the list still exists
  22.     {    //and is not "uninteractable" like a camera, or the cursor itself
  23.       if (_list[| i]) != id && !object_is_ancestor(_list[| i].object_index,par_oob)
  24.       {  
  25.         if target != noone //If I was over something
  26.         {
  27.           if instance_exists(target) //and it still exists
  28.           {
  29.             if target.depth > _list[| i].depth //and it's deeper than my new target
  30.             {
  31.               target = _list[| i];//Make the less deep object my target
  32.             }
  33.           }
  34.         }
  35.         if target == noone //If I wasn't over something to begin with
  36.         {
  37.           target = _list[| i]; //Make the hovered object the target
  38.         }
  39.         //show_debug_message(_list[| i].id);
  40.       }
  41.     }
  42.   }
  43. }
  44. else { target = noone; } //If it is just the cursor being seen, target noone
  45.  
  46. //If my target does not exist within the list of objects I am touching, target noone
  47. if ds_list_find_index(_list,target) == -1 { target = noone; }
  48.  
  49. ds_list_destroy(_list);//Cleanup
  50.  
  51. //show_debug_message("target: " + string(target));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement