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 ...
Get Android Game Programming: A Developer’s Guide 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.