Collision2D
A 2D collision detection library for modern HTML5 games by Richard Marks. Licensed under MIT. Copyright 2016, Richard Marks
What is it?
A small ES6 API for detecting 2D collisions between objects.
What kind of collision testing does Collision2D support?
- Rectangle vs Rectangle
- Circle vs Circle
- Rectangle vs Circle
- Alpha (pixel perfect)
- Alpha vs Rectangle
- Alpha vs Circle
- Alpha vs Alpha
How do I use Collision2D?
Install into your project with
npm install c2d --save-dev
Create colliders and test for collisions between two of them. Could not be any easier.
; // create colliders// displayObject should be an EaselJS DisplayObject instanceconst boxCollider = c2d;const circleCollider = c2d;const alphaCollider = c2d; // test collision between two objectslet objectsCollided = c2d;if objectsCollided console;
I see more in the source than that!
There are more functions available in Collision2D for advanced users. If you want to use the full API, simply change your import to the following
;
You now have access to everything in Collision2D.
Version 2.2 - last updated Apr 27, 2016