java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed.
I tried to only check for location if the actor is in the world but I feel I must of used the wrong coding.
This is the code for the actor being removed.
This is the code of the actor following the actor that will be removed if it catches it.
public class Person extends Actor
{
public static Person main;
private int i_MouseX,i_MouseY;
public Person() {
main = this;
}
public void act()
{
MouseInfo MI_ = Greenfoot.getMouseInfo();
if(MI_!=null)
{
i_MouseX=MI_.getX();
i_MouseY=MI_.getY();
}
setLocation(i_MouseX, i_MouseY);
Actor dead = getOneIntersectingObject(Animal.class);
if (dead != null) {
getWorld().removeObject(this);
return;
}
}
}public class Animal extends Actor
{
private int i_PersonX,i_PersonY;
public void act()
{
if(Person.main != null)
{
i_PersonX=Person.main.getX();
i_PersonY=Person.main.getY();
}
turnTowards(i_PersonX, i_PersonY);
move(1);
}
}
