• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

GM:Studio 1,Collision array?

andulvar

Member
I'm looking for a way to check a collision rectangle and return an array of all instance ids that fall within that collision area. Is there anything built-in to do this easily?

Edit: I should clarify, that using a with() function is not an option in this particular case as there will be thousands of instance ids to check and I do not want to iterate through them all.

Posted in the wrong section. Seems you can't delete your own threads?
 
Last edited:
J

Joshua Allen

Guest
You can try something like this:
Code:
/// instances_get(left, top, width, height);

var left    = argument0;
var top     = argument1;
var width   = argument2;
var height  = argument3;

instance_deactivate_region(left, top, width, height, false, true);
var OUT_ARRAY = 0;
var OUT_ARRAY_INDEX = 0;
with(all) {
    OUT_ARRAY[OUT_ARRAY_INDEX++] = id;
}
instance_activate_all();

return OUT_ARRAY;
or this:
Code:
/// instances_get(x1, y1, x2, y2, obj, prec, notme);

var x1    = argument0;
var y1    = argument1;
var x2    = argument2;
var y2    = argument3;
var obj   = argument4;
var prec  = argument5;
var notme = argument6;

var out_array = 0;
var out_array_index = 0;
var point_array = 0;

while(true) {
    var inst = collision_rectangle( x1, y1, x2, y2, obj, prec, notme );
    if (inst == noone) break;
    
    out_array[out_array_index] = inst;
    point_array[out_array_index, 0] = inst.x;
    point_array[out_array_index, 1] = inst.y;
    inst.x = -1000000;
    inst.y = -1000000;
    out_array_index++;
}

for(var i=0; i<array_length_1d(out_array); i++) {
    var inst = out_array[i];
    inst.x = point_array[i, 0];
    inst.y = point_array[i, 1];
}

return out_array;
 
Last edited by a moderator:
Top