pixel-perfect-collider
v1.0.1
Published
Pixel perfect collision detector
Downloads
2
Readme
pixel-perfect-collider
Pixel perfect collision detector.
Demo
How to use
See the sample code.
Include build/index.js script,
<script src="https://unpkg.com/pixel-perfect-collider/build/index.js"></script>
or install from npm.
> npm i pixel-perfect-collider
import * as ppc from "pixel-perfect-collider";
Create ppc.Collider
instance with a image whose collision should be detected.
this.image = new Image();
this.image.src = "star.png";
this.image.onload = () => {
this.collider = new ppc.Collider(this.image);
};
Set the position of the collider with Collider#setPos
function.
this.collider.setPos(x, y);
Use Collider#test
function to test a collision between two colliders.
stars[0].collider.test(stars[1].collider);