As the names suggest, the Begin Contact Event is called when two fixtures begin to overlap, while the End Contact Event is called when two fixtures cease to overlap.
Let's analyze the
BeginContact
function line by line:var fixtureA:b2Fixture=contact.GetFixtureA(); var fixtureB:b2Fixture=contact.GetFixtureB();
As you can see,
BeginContact
has ab2Contact
object passed as an argument. It contains all collision information we are looking for at the moment.GetFixtureA
andGetFixtureB
methods return the fixtures involved in the collision. I am saving them infixtureA
andfixtureB
variables.Then, as I am looking for bodies, I need to get the body from a fixture. You should already know about the
GetBody
method:var bodyA:b2Body=fixtureA.GetBody(); var bodyB:b2Body=fixtureB.GetBody();
Now
bodyA
andbodyB
are the colliding bodies. Time to print some text in the output window:trace("first body: "+bodyA.GetUserData()); trace("second body: "+bodyB.GetUserData...