The next type of body we can use to detect collisions is a circle. For that we are going to consider the diameter of the circle to be the largest of the dimensions of the sprite. We have to add a member variable to
mRadius and this code to the constructor of the sprite:
mRadius = Math.max(mHeight, mWidth)/2;
Note that other elements that inherit from
ScreenGameObject may want to initialize the radius in a different way.
The calculation of a circular collision is fairly simple: we just have to measure the distance between the centers of the two circles and check if it is smaller than the sum of the radius.