Detect when you are about to solve a collision and when you have solved it

The Pre-Solve Event is called after collision detection, but before collision resolution, so you can interact with a collision before it's solved. The Post-Solve Event occurs when a collision has been solved, and allows us to know the impulse of the collision.

  1. Add the following two functions to the customContact class:
    override public function PreSolve(contact:b2Contact, oldManifold:b2Manifold):void { if (contact.GetManifold().m_pointCount>0) { trace("a collision has been pre solved"); var fixtureA:b2Fixture=contact.GetFixtureA(); var fixtureB:b2Fixture=contact.GetFixtureB(); var bodyA:b2Body=fixtureA.GetBody(); var bodyB:b2Body=fixtureB.GetBody(); trace("first body: "+bodyA.GetUserData()); ...

Get Box2D for Flash Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.