Hello everyone!
I made a post like this before but I can't find it through my own profile. I will try to sum up my problem because I can show you guys my code now. I have unlimited enemys which are created from my world. They go from the top to the bottom and I want them to:
-Disappear when they reach the edge
-Disappear when the Player hits them 3 times
So I tried out this:
Now everytime they reach the edge they'll disappear like I wanted to but if I shoot them I get this message:
import java.util.*;
import greenfoot.*;
import java.awt.Color;
/**
*
*/
public class CopyOfEnemy extends Actor
{
private int hit = 0;
/**
*
*/
public CopyOfEnemy()
{
this.setRotation(-90);
}
/**
* Act Method
*/
public void act()
{
move(-3);
treffer();
}
/**
* Destroys the enemy when
*/
public void treffer()
{
if (hit < 3) {
if (isTouching(Schuss.class)) {
removeTouching(Schuss.class);
hit = hit + 1;
}
}
else {
this.getWorld().removeObject(this);
}
if (this.isAtEdge()) {
getOneIntersectingObject(CopyOfEnemy.class);
this.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.
at greenfoot.Actor.failIfNotInWorld(Actor.java:711)
I'm not a genius in things like these. I really hope that I can make my game and don't fail the whole thing because we get a grade for it :/ but like I said this is really really hard for me so it would be cool if you guys could lend me a hand!
