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 file. Remember to import sample projects.

How to do it…

In the next lines, ...

Get Libgdx Cross-platform Game Development Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.