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 live online training, plus books, videos, and digital content from nearly 200 publishers.