imShyness

Collision detection

Recommended Posts

Hello, I'm new to Pixi JS and I'm kinda stuck. 

So, I have about 5 containers which I can move (drag, drop), now when I drag one over the other, something has to happend.. an alert or whatever. 

How can I detect one container moving over the other?

 

Ty.

Share this post


Link to post
Share on other sites

You could do basic box collision detection if you dont need pixel perfect collisions.
 

function boxesIntersect(a, b)
{
  var ab = a.getBounds();
  var bb = b.getBounds();
  return ab.x + ab.width > bb.x && ab.x < bb.x + bb.width && ab.y + ab.height > bb.y && ab.y < bb.y + bb.height;
}

 

Share this post


Link to post
Share on other sites
12 hours ago, JackParke said:

Code above is incorrect. Should read:


return ab.x + ab.width > bb.x && ab.x < bb.x + bb.width && ab.y + ab.height > bb.y && ab.y < bb.y + bb.height;

Correction is: ab.y + ab.height > bb.y

Well spotted, fixed the error to original post.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.