1
當我的敵人到達屏幕的底部時,我想移除,如果敵人被子彈擊中,我想刪除它。錯誤是:java.lang.IllegalStateException:演員不在世界。試圖在不在世界中的情況下使用演員的位置。它或者尚未插入,或者已被刪除。Greenfoot演員不在世界錯誤
我認爲這個問題是因爲有兩個調用removeObject或getOneIntersectingObject方法導致錯誤。我該如何解決?
這是導致錯誤
public class Enemy extends Actor
{
public void act()
{
setLocation(getX(), getY() + 3);
if (getY() > getWorld().getHeight() + 30)
getWorld().removeObject(this);
Actor fire = getOneIntersectingObject(Fire.class);
if(fire != null)
getWorld().removeObject(this);
}
}