With this function you can check a position for a collision with all instances of another object. When you use this you are checking a single point in the room for all instances of an object, and the check will be done against the bounding box of the instances or against the mask of the instances if that object has precise collisions checked. The function will populate a (previously created) DS list with the unique id values of all instances of the object that are considered to be in collision with the calling instance, and you have the option to order the list based on the distance from the position being checked to the origin of the instances found to be in collision. Note that the function also accepts the special keyword all, in which case all instances found to be in collision will be listed. The function returns the number of instances found, or 0 if none are found.
instance_position_list(x, y, obj, list, ordered);
Argument Description x The x position to check for instances. y The y position to check for instances. obj The object to check for instances of. list The DS list to use to store the IDs of colliding instances. ordered Whether the list should be ordered by distance (true) or not (false).
Int (The number of instances found to be in collision)
var _list = ds_list_create();
var _num = instance_position_list(mouse_x, mouse_y, all, _list, false);
if _num > 0
for (var i = 0; i < _num; ++i;)
The above code will check for a collision with all instances found at the mouse position. These will be added to a DS list, which is then looped through to destroy each of the instances in collision.