collision_rectangle_list


Description

This function is the same as the collision_rectangle() function, only instead of just detecting one instance in collision at a time, it will detect multiple instances. You supply the x/y positions of the top left and bottom right of the area to check along with the object 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 which will be populated 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 center of the rectangular area 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.


Syntax:

collision_rectangle_list(x1, y1, x2, y2, obj, prec, notme, list, ordered);

Argument Description
x1 The x coordinate of the left side of the rectangle to check.
y1 The y coordinate of the top side of the rectangle to check.
x2 The x coordinate of the right side of the rectangle to check.
y2 The y coordinate of the bottom side of the rectangle to check.
obj The object to check for instance collisions.
prec Whether the check is based on precise collisions (true, which is slower) or its bounding box in general (false, faster).
notme Whether the calling instance, if relevant, should be excluded (true) or not (false).
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).


Returns:

Int (The number of instances found to be in collision)


Example:

var _list = ds_list_create();
var _num = collision_rectangle_list(x - 100, y - 100, x + 100, 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 rectangular area 100 pixels 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.