Hi I want to let my bullet dissapear after I kill an enemy. But I get the following termnal window:
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.isAtEdge(Actor.java:262)
at bullet.ifAtWorldEdge(bullet.java:37)
at bullet.act(bullet.java:21)
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)
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.isAtEdge(Actor.java:262)
at bullet.ifAtWorldEdge(bullet.java:37)
at bullet.act(bullet.java:21)
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)
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.isAtEdge(Actor.java:262)
at bullet.ifAtWorldEdge(bullet.java:38)
at bullet.act(bullet.java:21)
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)
This is my code:
What should I change??
public class bullet extends Actor { public bullet() { setImage("bullet.png"); //invoegen foto getImage().scale(35,35); //grootte foto } public void act() { move(20); //bewegen met snelheid 10 kill(); //de public "kill" uitvoeren ifAtWorldEdge(); //de public "ifAtWorldEdgde" uitvoeren } public void kill() { Actor Enemy; //het gaat over de actor Enemy Enemy = getOneObjectAtOffset(0, 0, Enemy.class); if (Enemy !=null) { World world; world = getWorld(); world.removeObject(Enemy); //de enemy laten verdwijnen world.removeObject(this); //de bullet laten verdwijnen } } public void ifAtWorldEdge() { if (isAtEdge()) //als dit object aan de buitekant is { getWorld().removeObject(this); //verwijder dan de bullet } } }