collision_line_list


描述

This function is the same as the collision_line() 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 start and end of the line 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 line 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. 函数返回找到的实例数,如果找不到,则返回 0。


语法:

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

参数 描述
x1 The x coordinate of the start of the line.
y1 The y coordinate of the start of the line.
x2 The x coordinate of the end of the line.
y2 The y coordinate of the end of the line.
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 用于存储碰撞实例的 ID 的数据结构列表。
ordered 列表是(true)否(false)应按距离排序。


返回:

Int(整数,发现碰撞的实例数)


例如:

var _list = ds_list_create();
var _num = collision_line_list(x - 100, y, x + 100, y, 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 line 100 pixels either side of 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.