实质是检测矩形与circle是否重叠
基本函数,判断点是否在circle中
1 public static boolean IsInside( float x, float y, Circle circle ){
2 float disX = x - circle.x;
3 float disY = y - circle.y;
4 return disX*disX + disY*disY <= circle.radius*circle.radius;
5 }
再判断矩形4个点是否在其中,有一个在即重叠
1 public static boolean IsOverlap( Actor actor, Circle circle ){
2 float x = actor.getX(), y = actor.getY(), w = actor.getWidth(), h = actor.getHeight();
3
4 return IsInside(x,y,circle) || IsInside(x+w,y,circle) || IsInside(x,y+h,circle) || IsInside(x+w,y+h,circle);
5 }
libgdx判断actor与circle是否重叠,布布扣,bubuko.com
时间: 2024-10-10 09:42:02