Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A different formulaic hit detect. This one works on rectangles
function recthit(rectone, recttwo){
console.log('recthit called');
var r1 = $(rectone);
var r2 = $(recttwo);
var r1x = r1.offset().left;
var r1w = r1.width();
var r1y = r1.offset().top;
var r1h = r1.height();
var r2x = r2.offset().left;
var r2w = r2.width();
var r2y = r2.offset().top;
var r2h = r2.height();
if( r1y+r1h < r2y ||
r1y > r2y+r2h ||
r1x > r2x+r2w ||
r1x+r1w < r2x ){
console.log('recthit-false')
return false;
}else{
console.log('recthit-true')
return true;
}
}//end function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment