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. ...

Get LibGDX Game Development By Example 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.