Hey everyone ,greenfoot newbie here. I'm making a game that consists on hunting birds with a bow and arrows. The thing is, I want the arrow to be removed when it touches the edge of the world.
Here is my code.
when i compile and throw an arrow to the edge it gives me this error
{
public void act()
{
// code that removes the arrow
if (isAtEdge())getWorld().removeObject(this);
else move(30);
arrowHit(null);
}
public void arrowHit(Class clss)
{
// code that removes the bird
if(isTouching(Bird.class))
{
removeTouching(Bird.class);
getWorld().removeObject(this);
}
}
}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.
If i change the
if (isAtEdge())getWorld().removeObject(this);
to
if (isAtEdge())move(0);
it works fine but the arrow gets stuck in the edge and its not want i want. Any advice?
