繁体   English   中英

libGDX,检测矩形之间的侧面碰撞(侧面碰撞)

[英]libGDX, detect side touching between rectangles (side collision)

我为我的游戏使用libGDX库。 用户overlap方法,用于检测两个矩形之间的碰撞检测。

...
if (r1.overlaps(r2)) collisionTest();
...

我想检测矩形(顶部,底部,左侧或右侧)的触摸侧:

r1 overlap r2 on the left side

任何人都可以给我这个代码,但这需要快速的方法。

谢谢

您可以使用该方法intersectRectangles所提供的Intersector类,以确定是否两个矩形是重叠的,如果是的话,它们重叠。 您可以使用此信息确定它们是否与左侧,右侧,顶部和/或底部重叠。

Rectangle r1 = /*Initialize*/;                             
Rectangle r2 = /*Initialize*/;                             
Rectangle intersection = new Rectangle();                  
Intersector.intersectRectangles(r1, r2, intersection);     
if(intersection.x > r1.x)                                  
    //Intersects with right side                              
if(intersection.y > r1.y)                                  
    //Intersects with top side                                
if(intersection.x + intersection.width < r1.x + r1.width)  
    //Intersects with left side                               
if(intersection.y + intersection.height < r1.y + r1.height)
    //Intersects with bottom side    

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM