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

Collisions

Well, so far so good. However, we haven't implemented any collision handling. Luckily, LibGDX contains really useful tools to check for collision between the shapes that we are using. This is going to make our lives a lot easier.

The one class we will use is the Intersector class. To find out more, visit http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Intersector.html and take a look at its API, you will see all sorts of useful methods there. However, we are only going to use two of them:

boolean overlaps(Circle c1, Circle c2)
boolean overlaps(Circle c, Rectangle r)

These will return true if the shapes overlap.

So, let's add a method to our Flower class that will take an instance of Flappee in and check the collision ...

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