1.0.1 • Published 6 years ago

pixel-perfect-collider v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

pixel-perfect-collider

Pixel perfect collision detector.

Demo

stars

stars screenshot

thread

stars screenshot

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);