The simplest collision detection in an Android game


The method getCollidePoint(Sprite s) returns the Point class. After that, as long as the collision Point exists, the method getCollidePoint(Sprite s) returns the Point class. The sprites of two games collide. The logic is relatively simple, use the setIntersect() method under the GRAPHICS package of the SDK to see if it intersects.

Public Point getCollidePoint(Sprite s){Point p = null; RectF rectF1 = getRectF(); RectF rectF1 = getRectF(); RectF rectF2 = s.getRectf (); RectF rectF2 = s.getrectf (); RectF RectF = new RectF(); // use the setIntersect() method to get the Boolean value of whether the two sprites intersect. If (isIntersect){// get intersection p = new Point(math.round (rectf.centerx ()), math.round (rectf.centery ())); } // return p; }Copy the code

This method can then be called, and when the Point is returned, as long as the Point exists, it means that the two sprites have collided, if not, it means that the two sprites have not collided. Also note that the getRectF() method, which gets the rectangle class of the bitmap in the Sprite, is self-written.

Copy the code