I got a java.lang.StackOverflowError because i spawned my Object (Flag) in my main scenario. I only want to spawn this object one time but i need to test the coordinates of this object. I don't know where i have to put my Flag Flag =new Flag().
I hope you can help me!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Main extends Actor
{
Flag Flag = new Flag();
public void act()
{
}
public boolean activ(Actor anActor)
{
return getWorld().getObjects(null).contains(anActor);
}
public void Walk()
{ if (activ(Flag)){
if (getX()<Flag.getX()){
setLocation(this.getX()+1, this.getY());
}
if (getX()>Flag.getX()){
setLocation(this.getX()-1, this.getY());
}
if (getY()<Flag.getY()){
setLocation(this.getX(), this.getY()+1);
}
if (getY()>Flag.getY()){
setLocation(this.getX(), this.getY()-1);
}
}
}
}

