Collision function

We defined our collision behavior, but it is also necessary that we write a logic that defines our collision itself. So, we make a collision detection function:

public boolean collision(GameObj a, GameObj b) {    if(Rect.intersects(a.getRectangle(), b.getRectangle())) {        return true;    }    return false;}

Our collision function is now ready.

Get Learning Android Game Development 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.