Say, I have 3 bodies - A, B, C. I want to have a different action performed for each type of collision: A - B, B - C, C - A. In APE, you could set Collision Event Listeners for each body. When a collision event is fired, you could then retrieve the name of the body with which it has collided and carry out functions.
In Box2D, I could find only the following method:
Is that the only way to do it? Or is there an easier way? Isn't this process a little tedious for a large number of bodies?
In Box2D, I could find only the following method:
Code:
for (var c: b2Contact = m_world.GetContactList() ; c ; c = c.GetNext())
{
// A positive manifold count ensures that the shapes are actually touching.
if (c.GetManifoldCount() > 0)
{
var body1: b2Body = c.GetShape1().GetBody();
var body2: b2Body = c.GetShape2().GetBody();
if( (body1 == A || body2 == A) && (body1 == B || body2 == B) )
{
...
}
if( (body1 == B || body2 == B) && (body1 == C || body2 == C) )
{
...
}
if( (body1 == C || body2 == C) && (body1 == A || body2 == A) )
{
...
}
}
}
{
// A positive manifold count ensures that the shapes are actually touching.
if (c.GetManifoldCount() > 0)
{
var body1: b2Body = c.GetShape1().GetBody();
var body2: b2Body = c.GetShape2().GetBody();
if( (body1 == A || body2 == A) && (body1 == B || body2 == B) )
{
...
}
if( (body1 == B || body2 == B) && (body1 == C || body2 == C) )
{
...
}
if( (body1 == C || body2 == C) && (body1 == A || body2 == A) )
{
...
}
}
}
Is that the only way to do it? Or is there an easier way? Isn't this process a little tedious for a large number of bodies?