Reacting to collisions
Box2D takes collision response to an awesome level of realism where bodies act exactly as expected in most cases. However, there are a lot of situations within a game that demand custom collision dealing, such as receiving damage, controlling a ball, or simply pushing enemies.
After reading this recipe, you will easily be able to manage those special circumstances that will surely appear in your game.
Getting ready
The sample code will implement a balloon-breaker mini-game where a shuriken will follow your cursor looking for fragile balloons to destroy before they leave the scene dimensions.
You can find the code within the Box2DCollisionReactionSample.java
file. Remember to import sample projects.
How to do it…
In the next lines, ...
Get Libgdx Cross-platform Game Development Cookbook 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.