java – libGDX,检测矩形之间的接触(侧面碰撞)
发布时间:2020-12-15 04:18:43 所属栏目:Java 来源:网络整理
导读:我为我的游戏使用libGDX库.用户重叠方法,用于检测两个矩形之间的碰撞检测. ...if (r1.overlaps(r2)) collisionTest();... 我想检测矩形(顶部,底部,左侧或右侧)的触摸侧: r1 overlap r2 on the left side 任何人都可以给我这个代码,但这需要快速的方法. 谢谢
我为我的游戏使用libGDX库.用户重叠方法,用于检测两个矩形之间的碰撞检测.
... if (r1.overlaps(r2)) collisionTest(); ... 我想检测矩形(顶部,底部,左侧或右侧)的触摸侧: r1 overlap r2 on the left side 任何人都可以给我这个代码,但这需要快速的方法. 谢谢 解决方法
您可以使用Intersector类中提供的intersectRectangles方法来确定两个矩形是否重叠,如果是,则重叠的位置.您可以使用此信息确定它们是否与左侧,右侧,顶部和/或底部重叠.
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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |