【发布时间】:2016-11-21 13:28:34
【问题描述】:
// 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);
}
}
}
}
不知何故,人类(h1 和 h2)的所有对象都是 setX(h1.getX() + 2);。如何解决?我只需要他们中的一个让开
【问题讨论】:
标签: libgdx collision-detection collision