O'Reilly logo

Android Game Programming by Example by John Horton

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

Multiphase collision detection

We have seen that our player character simply falls though the world and into oblivion. Of course we need the player to be able to stand on the platforms. Here is what we will do.

We will provide every object that matters with a hitbox as we can then provide methods in the Player class to test if a hitbox has made contact with the player. Once per frame, we will send all hitboxes that have not been clipped by the viewport to this new method where a collision can be tested for.

We do it like this for two main reasons. Firstly, by sending only unclipped hitboxes for collision testing, we drastically reduce the number of checks, as described in Chapter 3, Tappy Defender – Taking Flight, in the section Things that go bump ...

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