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);
。如何解決它?我只需要其中的一個退居二線