collision_circle_list

This function is the same as the collision_circle() function, only instead of just detecting one instance / tile map in collision at a time, it will detect multiple instances or tile maps. You supply the x/y position of the center of the circular area to check along with the radius and the object / tile map to check for, and you can set the check to be precise (in which case all instances being checked will need to have precise collision masks) and whether the check should include the calling instance or not.

You supply a DS list too, so the id values of any instances (or tile maps) that are colliding with the calling instance will be added to the end of the given list. You can clear the list before calling this function so that it only contains results from this function call. You also have the option to order the instances based on their distances from the origin of the circular area to their origins. The function returns the number of instances / tile maps found, or 0 if none are found.

In addition to objects and instances, the function also accepts:

Passing an array allows you to check for collisions against multiple objects and/or Tile Maps in one call.

 

Syntax:

collision_circle_list(x1, y1, rad, obj, prec, notme, list, ordered);

ArgumentTypeDescription
x1RealThe x coordinate of the center of the circle to check.
y1RealThe y coordinate of the center of the circle to check.
radRealThe radius (distance in pixels from its center to its edge).
objObject Asset or Object Instance or Tile Map Element ID or ArrayAn object, instance, tile map ID, keywords all/other, or array containing these items
precBooleanWhether the check is based on precise collisions (true, which is slower) or its bounding box in general (false, faster).
notmeBooleanWhether the calling instance, if relevant, should be excluded (true) or not (false).
listDS ListThe DS list to use to store the IDs of colliding instances.
orderedBooleanWhether the list should be ordered by distance (true) or not (false).

 

Returns:

Real (The number of instances / tile maps found to be in collision)

 

Example:

var _list = ds_list_create();
var _num = collision_circle_list(x, y, 100, obj_Enemy, false, true, _list, false);
if (_num > 0)
{
    for (var i = 0; i < _num; ++i;)
    {
        instance_destroy(_list[| i]);
    }
}
ds_list_destroy(_list);

The code above will check a circular area with a 100 pixel radius around the calling instance position for collisions with instances of "obj_Enemy". If there are any collisions, then the pre-created list is looped through and each instance that was in the collision is destroyed.