This code below is suppose to get the object to disappear at the world edge but I get a this run time error:
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.
at greenfoot.Actor.failIfNotInWorld(Actor.java:663)
at greenfoot.Actor.getX(Actor.java:157)
at Bullets.disappearAtEdge(Bullets.java:84)
at Bullets.act(Bullets.java:60)
private void disappearAtEdge()
{
if (getX() == 0 || getX() == getWorld().getWidth()-1) //if the x location 0 or it is one less than
//it is one less than width of the world
{
World world = getWorld(); //assign world to getWorld
NoMansLand noMansLand = (NoMansLand) getWorld(); //creates a cast to call the gameOver() method
noMansLand.removeObject(this);
}
else if (getY() == 0 || getY() == getWorld().getHeight()-1) //if the y location 0 or it is onle less than
//it is one less than width of the world
{
World world = getWorld(); //assign world to getWorld
NoMansLand noMansLand = (NoMansLand) getWorld(); //creates a cast to call the gameOver() method
noMansLand.removeObject(this);
}
}

