I'm trying to kill an enemy when jump on it, with this code
public void enemyDie()
{
Actor player = getOneObjectAtOffset(0, getImage().getHeight()/2, Player.class);
if (player!=null)
{
World myWorld = getWorld();
myWorld.removeObject (this);
}
}
and i'm have this 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:711)
at greenfoot.Actor.getOneObjectAtOffset(Actor.java:913)
at FlyingMod.onGround(FlyingMod.java:120)
at FlyingMod.checkFall(FlyingMod.java:145)
at FlyingMod.act(FlyingMod.java:29)
at greenfoot.core.Simulation.actActor(Simulation.java:604)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:562)
at greenfoot.core.Simulation.runContent(Simulation.java:221)
at greenfoot.core.Simulation.run(Simulation.java:211)
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:711)
at greenfoot.Actor.getOneObjectAtOffset(Actor.java:913)
at FlyingMod.onGround(FlyingMod.java:120)
at FlyingMod.checkFall(FlyingMod.java:145)
at FlyingMod.act(FlyingMod.java:29)
at greenfoot.core.Simulation.actActor(Simulation.java:604)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:562)
at greenfoot.core.Simulation.runContent(Simulation.java:221)
at greenfoot.core.Simulation.run(Simulation.java:211)
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:711)
at greenfoot.Actor.getOneObjectAtOffset(Actor.java:913)
at FlyingMod.onGround(FlyingMod.java:120)
at FlyingMod.checkFall(FlyingMod.java:145)
at FlyingMod.act(FlyingMod.java:29)
at greenfoot.core.Simulation.actActor(Simulation.java:604)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:562)
at greenfoot.core.Simulation.runContent(Simulation.java:221)
at greenfoot.core.Simulation.run(Simulation.java:211)
