Thanks people, I seem to have gotten it right,
collidesWith(object1,object2);{
if (instance_exists(argument[0]) && instance_exists(argument[1]))
{
return real(argument[0].bbox_left < argument[1].bbox_right &&
argument[0].bbox_right > argument[1].bbox_left &&
argument[0].bbox_top < argument[1].bbox_bottom &&
argument[0].bbox_bottom > argument[1].bbox_top);
}
}I had a suspicion bbox_ also matched the position/size of the object.
var i;
i=argument[0]; //Just to make it less to write!
if collision_rectangle(i.x, i.y, i.x+i.sprite_width, i.y+i.sprite_height, argument[1], false, true) return 1 else return -1;
//Or even
return collision_rectangle(i.x, i.y, i.x+i.sprite_width, i.y+i.sprite_height, argument[1], false, true);
//which will return true or false (actually -4(noone) or the id, but the result is still true or false!);
Yes, I'll have to try the above code with bbox.
edit: yes, suppose it will be faster using the native collision_rectangle instead,
{
if (collision_rectangle(argument[0].bbox_left, argument[0].bbox_top, argument[0].bbox_right, argument[0].bbox_bottom, argument[1], false, true))
{
return true;
}
else
{
return false;
}
}
Edited by Sindarin, 30 August 2011 - 07:34 PM.