Alternatively, categories & masks can be used.
When defining a ShapeDef or its various subclasses (PolygonDef, CircleDef, etc.) you can define a "categoryBit" to identify a group of shapes with the "maskBits" field.
If you want no collisions on an object whatsoever, set its maskBits to 0x0000; the default, aka "collide with everything," is 0xffff:
Code:// No collisions
shapeDef.filter.maskBits = 0x0000;
// Collide with all (except for those with collisions turned off)
shapeDef.filter.maskBits = 0xffff;
If you want a specific group to collide only with another specific group, define each groups' categoryBits separately, then point each groups' maskBits to the others' category:
Code:// Categories are defined for each shape in each group
group1shapeDef.filter.categoryBits = 0x0001;
group2shapeDef.filter.categoryBits = 0x0002;
// This will only allow the two groups to collide with each other and nothing else
group1shapeDef.filter.maskBits = 0x0002;
group2shapeDef.filter.maskBits = 0x0001;
// This will allow the two groups to collide with everything EXCEPT the other group
group1shapeDef.filter.maskBits = 0xffff & ~0x0002;
group2shapeDef.filter.maskBits = 0xffff & ~0x0001;
I hope this helps other people understand this better. The original Box2D manual doesn't explain it very well. Thanks to this post at the box2d forums for helping me understand it:
http://www.box2d.org/forum/viewtopic.php?f=3&t=197