Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

rect to rect collision

var rect1 = {x: 5, y: 5, width: 50, height: 50}
var rect2 = {x: 20, y: 10, width: 10, height: 10}

if (rect1.x < rect2.x + rect2.width &&
   rect1.x + rect1.width > rect2.x &&
   rect1.y < rect2.y + rect2.height &&
   rect1.y + rect1.height > rect2.y) {
    // collision detected!
}

// filling in the values =>

if (5 < 30 &&
    55 > 20 &&
    5 < 20 &&
    55 > 10) {
    // collision detected!
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: urlsearchparams to object 
Javascript :: javascript filter array by groups of highest 
Javascript :: delete file with deno 
Javascript :: How to pass setInterval() into a Javascript class method 
Javascript :: javascript jquery map a range of numbers 
Javascript :: emacs change text size 
Javascript :: using arrow function and destructuring 
Javascript :: string.fromcharcode 
Javascript :: javascript things to remember 
Javascript :: javascript how to deal with %20 in string 
Javascript :: how to sho the active navigation ling using javascript 
Javascript :: javascript array randomizer 
Javascript :: card type through card number 
Javascript :: blur effect javascript 
Javascript :: change build directory react 
Javascript :: online javascript compiler 
Javascript :: anguler test submit form 
Javascript :: how to add multiple elements to A new array javascript 
Javascript :: Routes in react-router-dom@6 and take the path by useLocation() hook 
Javascript :: multiple conditions for JavaScript .includes() method 
Javascript :: jquery append after number of chars in string 
Javascript :: for loop java script 
Javascript :: Accessing Object Properties with Variables 
Javascript :: jQ - on image load 
Javascript :: expressjs req.body.parameters 
Javascript :: var js 
Javascript :: why array.map returns undefined 
Javascript :: Content security policy (csp) javascript 
Javascript :: socket.id 
Javascript :: javascript closure function example 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =