Hi guys, it's me again (sry 'bout that lol)
Well I have a bullet class and when I try to run the program it says
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:656)
at greenfoot.Actor.getOneObjectAtOffset(Actor.java:860)
//..............
//(Some more codes here, if I paste them all it'll be very confusing so..)
So now I have a bullet class, so it's basically like... when I press space a bullet comes out.
Everything works well until the bullet reaches the edge of the window OR an object (another actor. A zombie, for example)
It says 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.
I tried to find the error in the internet, it says this error would be thrown if there's something wrong with the
getX method. Do I need to add something before that? Actually I think I need to post my bullet codes too..
public void act()
{
setLocation(.getX(),getY()-10);
checkEdge(getY());
checkKill();
}
public void checkEdge(int y){
if (y < getWorld().getHeight()-598)
{
getWorld().removeObject(this);
}
}
public void checkKill()
{
Actor zombie;
zombie = getOneObjectAtOffset(0,0,Zombie.class);
if(zombie!=null)
{
World world;
world = getWorld();
world.removeObject(zombie);
Greenfoot.playSound("zombieDeath.wav");
}
}
Hope it's not too confusing lol...
Thanks a lot guys ;)