Using preSolve and postSolve
Making use of the available data for a collision inside the contact listener's presolve
method, which is called before the Box2D iterator causes a reaction, allows us to have unique control over how our collisions occur. The preSolve()
method is most commonly used to create “one-way” platforms that a character can jump through from below while still being able to walk on them from above. The postSolve()
method, which is called after a reaction has been set in motion, gives us the corrective data, also known as the
impact force, for the collision. This data can then be used to destroy or break apart objects. In this recipe, we will demonstrate how to properly use the preSolve()
and postSolve()
methods of a ContactListener
interface.
Getting ready...
Create a new activity by following the steps in the Introduction to the Box2D physics extension section given at the beginning of the chapter. This new activity will facilitate our use of the preSolve()
and postSolve...