Iterator<Rectangle> iter = incomingCars.iterator();
while (iter.hasNext()) {
Rectangle incomingCar = iter.next();
incomingCar.y -= score/2+200 * Gdx.graphics.getDeltaTime();
}
if(incomingCar.overlaps(car)) {
iter.remove();
}
}
关于这个非常接近的教程并且它仍在搞乱,在两个矩形之间检测到0个检测/碰撞。
public void create() {
car = new Rectangle();
car.x = 180;
car.y = 0;
car.height = 172;
car.width = 100;
incomingCars = new Array<Rectangle>();
}
private void spawnCar() {
int lane;
Rectangle incomingCar = new Rectangle();
lane = MathUtils.random(0, 2);
if (lane == 0) {
incomingCar.x = 30;
}
if (lane == 1) {
incomingCar.x = 180;
}
if (lane == 2) {
incomingCar.x = 330;
}
incomingCar.y = 1000;
incomingCars.add(incomingCar);
所以我现在会尝试调试这些东西,但我觉得我错过了一些稍微重要的东西。我必须在这里添加一些额外的细节,不知道该说些什么,我想我会试着检查这些车是否真的以任何方式碰撞。