Hello,
i need a solution for a simple Collision detection from GUI Elements in JS:
This here will just a detection form left upper Corner of elem_2 with elem_1:
if (elem_1.Contains(Vector2(elem_2.x,elem_2.y))) {
//hit
}
But i need a detection of all.
The Rect structure has xMin, xMax, yMin and yMax values that give the X and Ycoordinates of each edge of the rectangle (for example, xMin gives the X coordinate of the left side). You can use these properties to check if two rectangles overlap:-
function RectsOverlap(r1: Rect, r2: Rect) {
var widthOverlap = (r1.xMin >= r2.xMin) (r1.xMin <= r2.xMax) ||
(r2.xMin >= r1.xMin) (r2.xMin <= r1.xMax);
var heightOverlap = (r1.yMin >= r2.yMin) (r1.yMin <= r2.yMax) ||
(r2.yMin >= r1.yMin) (r2.yMin <= r1.yMax);
return widthOverlap heightOverlap;
}