What code can I use if for example, Object A is the player, Object B is a moving object. If Object A hits Object B it can either be that Object A will be remove or Object A is respawned to its initial location.
//in your A class;
public boolean touchingObjectB() {
return !getOneIntersectingObject(B.class).isEmpty();
}
//instead of B.class you have to use the real classname;//again in your class A;
public void act() {
if (touchingObjectB()) {
if (respawn) {//you have to know whether you want to remove or respawn;
//here your actor is respawned;
getWorld().addObject(new A(), 5, 5);//here you have to use the right classname and the right coordinates for the respawn;
getWorld().removeObject(this);
}
else {
//here your object just gets removed;
getWorld().removeObject(this);
}
}
}public boolean touchingObjectB() {
return !getIntersectingObjects(B.class).isEmpty();
} public boolean touchingObjectB() {
return (getOneIntersectingObject(B.class) != null);
}