O'Reilly logo

LibGDX Game Development By Example by James Cook

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Collision detection

So here we are. We have Pete wandering around on the screen, with the ability to jump, and looking pretty snazzy. We need to take the next step and have him interact with the level we created.

When it comes to collision detection, there is a vast array of different methods, concepts, and techniques that get used when making platformers. However, for what we are trying to achieve here, giving you a taster on using LibGDX to make games, we can take a simplistic approach.

The approach we are going to take is a two-phase detection. Firstly, we find out what cells Pete is currently covering, and then we work out if these cells contain the solid ground tiles. Then, we will resolve the collision by moving Pete out of the cells area. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required