Physics Collision Library

503
Vote up!

To help with the calculation of physics collision categories and masks there is an excellent table available:
http://forums.coronalabs.com/topic/2128-collision-filters-helper-chart/

If you would rather use names for your categories and have the masks generated for you, you can use this library.

It's simple: Just think of a category name for each object you have and create masks for all the objects to collide with.

This Gist includes the collisionslib.lua and a modified main.lua for the "CollisionFilter" sample from the Corona SDK samples directory.

To use the library:
local collisionslib = require("collisionslib")

To create a filter mask:
local redCollisionFilter = { categoryBits = collisionslib.getCategory("red"), maskBits = collisionslib.getMask("border","red") }

  • getCategory() takes the name of your object
  • getMask() takes the names of the other objects which your first object collides with
Contributor: 
HoraceBury