Libgdx 使用自制类,然后已经可用(矩形包含,重叠方法)

Libgdx 使用自制类,然后已经可用(矩形包含,重叠方法),libgdx,Libgdx,这个代码我见过很多次 if (OverlapTester.pointInRectangle(playRegion, touchPoint.x, touchPoint.y)) { game.setTransitionScreen(game, new LevelScreen(game)); return; } 班级:: public class OverlapTester { public static boolean pointInRectangle (Rectang

这个代码我见过很多次

if (OverlapTester.pointInRectangle(playRegion, touchPoint.x, touchPoint.y)) {
     game.setTransitionScreen(game, new LevelScreen(game));
     return;
}
班级::

public class OverlapTester {
    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;
    }
}
公共类重叠测试仪{
公共静态布尔点透视角(矩形r、浮点x、浮点y){
返回r.x=x&&r.y=y;
}
}

我不明白为什么会这样做??当libgdx已经提供了rectangle.contains(rec)和overlap方法时。

实际上不需要这个类

不仅因为矩形有一个方法可以做同样的事情,还因为还有一个方法也提供了这一点<代码>交集有更多功能。它可以用于所有类型的交叉点和其他事物的重叠,而不仅仅是矩形

为了使碰撞检查更加一致,您可能应该使用
Intersector
而不是
Rectangle
方法,但实际上也是这样