Warning

For best results, use integers.
If you're using gl-matrix, you can simply
swap out vec2.create with vec2.create = function() { return new Int32Array(2) }.

API

collision(field, tilesize[, dimensions]) -> collide function

Produces a collide(aabb, vec2, oncollide) function.

field may be a single-dimension array of integers (in which case dimensions can be inferred if not provided), or it may be a function in the form fn(tile_x_idx, tile_y_idx) -> tile data integer. if it's a function, dimensions is required.

tilesize is the pixel size of a tile.

dimensions is an array of integers [width, height].
if it is not provided it will attempt to set to [Math.sqrt(field.length), Math.sqrt(field.length)] (that is, it assumes a square tilemap).

collide(aabb, vec, oncollide) -> undefined

attempt to advance aabb by vec against the tilemap. destructive, it will actually call aabb.translate.