This is mask
, a tiny MIT-licensed library providing collision masks
and thus pixel-perfect collision detection in JavaScript. Collision
masks are read from PBM files.
PBM is a minimalistic monochrome image format. One variant of it looks like this:
P1
10 10
0000000000
0111111110
0110000010
0101000010
0100110010
0100110010
0100001010
0100000110
0111111110
0000000000
There are a number of tools to make PBM images -- ImageMagick's
convert
tool will do it, and NetPBM provides a suite of
confusing tools for working with it and its sister formats. You
probably want something like
pngtopnm < in.png | pamditherbw | pamtopnm > out.pbm
.
You probably want Mask.PBM.url
, Mask.collision
, and
Mask#within
. There are some just-alright docs. The source is
well-commented and not difficult; might as well take a look.
Pull requests are welcome; tests and jslint compliance are appreciated.