newRed() work fine but newBlue() does not and the error only happens when i press spacebar and thats in newRed()
public boolean canSee(Class clss)
{
Actor actor = getOneObjectAtOffset(0, 0, clss);
return actor != null;
}
public void newRed()//works fine
{
if(canSee(Player2.class)&&Greenfoot.isKeyDown("space"))
{
World k = getWorld();
k.addObject(new RedBlock(),getX(),getY());
Greenfoot.delay(5);
k.removeObject(this);
}
}
public void newBlue()//error-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.
{
if(canSee(Player1.class)&&Greenfoot.isKeyDown("enter"))
{
//getWorld();
getWorld().addObject(new BlueBlock(),getX(),getY());
Greenfoot.delay(5);
getWorld().removeObject(this);
}
}

