I have a problem. Im currently programming a game as a school project. In my game, there is a hero an enemies, which the hero can kill after 3 hits.
However, when I kill an enemy it gives me the following error:
greenfoot.ActorRemovedFromWorld
at greenfoot.World.removeObject(World.java:466)
at Gegner.hit(Gegner.java:136)
at Gegner.act(Gegner.java:25)
... 4 more
How can i fix this? Nothing I have tried worked so far.
public void act() { count++; hit(); move(); falling(); checkFalling(); onPlatform(); randomSpawn(); randomjump(); } public void move() { if (count < 120) setLocation(getX() + speed, getY()); else{ speed = -speed; getImage().mirrorHorizontally(); count = 0; } } public void falling() { this.setLocation(this.getX(), this.getY() + verticalSpeed); verticalSpeed = verticalSpeed + 1; } public void checkFalling() { if(onPlatform()) { verticalSpeed = 0; } else { falling(); } } public boolean onPlatform() { Actor under = getOneObjectAtOffset (0, getImage().getHeight()/2, Ground.class); return under != null; } public void randomSpawn() { if (getWorld() != null && getWorld().getObjects(Gegner.class).size() < 4 && Greenfoot.getRandomNumber(200) == 1) { Actor Gegner = new Gegner(); getWorld().addObject(Gegner, 50, 187); if (Greenfoot.getRandomNumber(2) == 1) { Gegner.setLocation(630, 50); } if (Greenfoot.getRandomNumber(2) == 1) { Gegner.setLocation(Gegner.getX(), 450); Gegner.setRotation(-Gegner.getRotation()); } } } public void randomjump() { if( onPlatform() && Greenfoot.getRandomNumber(80) ==3) { jump(); } } public void jump() { verticalSpeed = 2 +jumpStrength; falling(); } public void hit() { Actor projektil = getOneIntersectingObject(Projektil.class); if(projektil != null && !hit) { hp--; hit = true; getWorld().removeObject(projektil); } else if(!isTouching(Projektil.class)) { hit = false; } if (hp <= 0) { getWorld().removeObject(this); } } }