Book Image

Libgdx Cross-platform Game Development Cookbook

Book Image

Libgdx Cross-platform Game Development Cookbook

Overview of this book

Table of Contents (20 chapters)
Libgdx Cross-platform Game Development Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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, you will find the content of the Box2DCollisionReactionSample.java file broken down into nine steps:

  1. Initialize Viewport, SpriteBatch, World, Box2DDebugRenderer, and a groundBody for our scene. Feel free to go back to the first recipe of this chapter...