I have a theoretical answer.
If I code this behavier, I get a nullPointerException
If I change the coding a little bit, I get no error.
It is logical for me, that if an object is removed it is not possibe to turn or to setLocation any more.
If an object is removed in the end of the act-method, why does it work? After been removed it should go on turning and setLocation and get a NullpointerException too...
I would be happy for an explanation or for a better solution.
Thanks a lot
Wueschn
public class Ants extends Actor
{
public void act()
{
this.touchingTheEdge();
this.turn(3);
this.setLocation(this.getX() + 2, this.getY());
}
public void touchingTheEdge()
{
if(this.isAtEdge())
{
this.getWorld().removeObject(this);
}
}
}public class Ants extends Actor
{
public void act()
{
this.turn(3);
this.setLocation(this.getX() + 2, this.getY());
this.touchingTheEdge();
}
public void touchingTheEdge()
{
if(this.isAtEdge())
{
this.getWorld().removeObject(this);
}
}
}
