0
// array containing the active humans.
public final Array<Human> activeHumans = new Array<Human>();
// object pool.
public final Pool<Human> humanPool = new Pool<Human>() {
@Override
protected Human newObject() {
return new Human(100, 500);
}
};
............................................. ...............................Как сделать обработку столкновений для объектов одного класса?
@Override
public void update(float dt) {
checkCollisions();
}
public void checkCollisions() {
// human-human collision
for (int i=0; i<activeHumans.size(); i++) {
Human h1 = activeHumans.get(i);
for (int j=0; j<activeHumans.size(); j++) {
Human h2 = activeHumans.get(j);
if (h1.getRectangle().overlaps(h2.getRectangle())) {
h1.setX(h1.getX() + 2);
}
}
}
}
Как-то все объекты Human (h1 и h2) делают setX(h1.getX() + 2);
. Как это исправить? Мне нужен только один из них отошел в сторону