+ 3
[Solved] Q. Please help in collision or overlapping figure canvas detector.
I have two rectangles. Both are constantly moving. I need to give a alert as soon as they both touch each other.
3 odpowiedzi
+ 3
E_Y7-2_D REY MANTECAS I've mentioned it in the question. Their are two rectangles which are constantly moving.
+ 2
Hint:
//Two rectangle collision detection
function rectscollision(rectA, rectB) {
return !(rectA.x + rectA.width < rectB.x ||
rectB.x + rectB.width < rectA.x ||
rectA.y + rectA.height < rectB.y ||
rectB.y + rectB.height < rectA.y);
};
For more please save your code on Sololearn playground and link here.
+ 2
If(rectA.x > rectB.x && rectA.x < rectB.x + rectB.width{
If(rectA.y > rectBy. && rectA.y < rectB.x + rectB.height){
Collision
}
}
If(rectA.x + rectA.width > rectB.x && rectA.x < rectB.x + rectB.width{
If(rectA.y> rectBy. && rectA.y < rectB.x + rectB.height){
Collision
}
}
If(rectA.x > rectB.x && rectA.x < rectB.x + rectB.width{
If(rectA.y + rectA.height> rectBy. && rectA.y < rectB.x + rectB.height){
Collision
}
}
If(rectA.x + rectA.width> rectB.x && rectA.x < rectB.x + rectB.width{
If(rectA.y + rectA.height> rectBy. && rectA.y < rectB.x + rectB.height){
Collision
}
This should work
}