showing results for - "rect to rect collision"
Marco
26 Aug 2016
1var rect1 = {x: 5, y: 5, width: 50, height: 50}
2var rect2 = {x: 20, y: 10, width: 10, height: 10}
3
4if (rect1.x < rect2.x + rect2.width &&
5   rect1.x + rect1.width > rect2.x &&
6   rect1.y < rect2.y + rect2.height &&
7   rect1.y + rect1.height > rect2.y) {
8    // collision detected!
9}
10
11// filling in the values =>
12
13if (5 < 30 &&
14    55 > 20 &&
15    5 < 20 &&
16    55 > 10) {
17    // collision detected!
18}
19