public static boolean pointInRectangle (Rectangle r, float x, float y) { return r.x <= x && r.x + r.width >= x && r.y <= y && r.y + r.height >= y;}在您的更新中-
if(pointInRectangle(flyRectangle, Gdx.input.getX(), Gdx.input.getY())){ // Do whatever you want to do with the rectangle. maybe register them for effect}您也可以查看Intersector类。
现在要进行碰撞,如果您的游戏节奏快,并且有很多敌人可以与玩家碰撞,那么您迟早会使用box2d类型库,因为如果移动速度很高,您可能不会得到任何碰撞回调。事情可能会相互贯穿。您可以使用速度和deltaTime尝试在碰撞发生之前进行预测,但是仍然远远不够,最终将需要重新设计轮子。
Mario的SuperJumper是启动libGDX的绝佳演示。试试吧。
编辑:
有一个实例成员-
Vector3 touchPoint;
在创建时
touchPoint = new Vector3();
更新时
camera.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));if (Gdx.input.justTouched()) { if (pointInRectangle(rectangle, touchPoint.x, touchPoint.y)) { }}请注意libGDX中的坐标系。为了进行测试,请在屏幕上创建一个矩形。单击时,打印/调试矩形和touchPoint的坐标。



