【发布时间】:2015-10-07 18:25:35
【问题描述】:
我正在尝试在我的Player(演员)和我的Obstacle(演员)之间实现碰撞检测器,我想知道在它们之间执行collision detection 的最佳方法是什么。我看到一些用户说他们在课堂上创建了一个Rectangle object 并每帧更新它的边界,但我不知道这是否是执行此操作的最佳方法(我也在尝试这样做,但我的碰撞检测器方法在我的玩家接触障碍物之前触发)。
这是我要检查的内容:
public boolean touchedWall() {
// Loop for the obstacles
for (Obstacle obstacle : this.world.getObstacles()) {
// Check if player collided with the wall
if (this.bounds.overlaps(obstacle.getBounds())) {
Gdx.app.log(Configuration.TAG, "collided with " + obstacle.getName());
return true;
}
}
return false;
}
这是方法触发的地方(它应该在玩家边界撞墙时触发):
【问题讨论】:
-
“this.bounds.overlaps(obstacle.getBounds())”中引用的“边界”类型是什么?
-
在这两个演员中我都这样做了:
private Rectangle bounds。这是你想知道的吗?我不知道为什么会这样,因为我做了 Rectangle 的 X 位置和演员边界的 X 位置之间的差异,结果是 0。