Chapter 5. Handling Collisions

Given a Box2D world and some moving bodies, sooner or later two of them will collide. Physics games rely on collisions for most gameplay features. When a bird smashes pig's castle in Angry Birds, it is thanks to collisions; when the idol falls down the totem and breaks on the ground, that's due to collisions.

Box2D already does all the required tasks to solve collisions and run the simulation without any coding on our part. By the way, in some situations, we need to interact with collisions for a gameplay purpose.

Think about Angry Birds, hitting hard on a wooden wall will break it, but normal Box2D collision routines do not manage wooden wall breaking. Moreover, if the Totem Destroyer idol hits the ground, the level ...

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.