Hello,
I'm trying to make my actor get removed from the screen when it crosses a world edge. However, I'm receiving an illegal state exception. Can someone please help? Thank you.
Here's the exception:
Here's my act method:
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:713) at greenfoot.Actor.getY(Actor.java:178) at Bomb.act(Bomb.java:28) at greenfoot.core.Simulation.actActor(Simulation.java:567) at greenfoot.core.Simulation.runOneLoop(Simulation.java:530) at greenfoot.core.Simulation.runContent(Simulation.java:193) at greenfoot.core.Simulation.run(Simulation.java:183)
public void act() { // Add your action code here. move(3); if (getWorld() != null){ if (getX() > getWorld().getWidth()){ getWorld().removeObject(this); } if (getY() < 0){ getWorld().removeObject(this); } if (getY() > getWorld().getHeight()){ getWorld().removeObject(this); } } }