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)
at greenfoot.Actor.getOneObjectAtOffset(Actor.java:913)
at Bullet.hitBoss(Bullet.java:26)
at Bullet.act(Bullet.java:37)
I receive this error when shooting an enemy with a bullet. I thought that the line saying if boss!= null would stop this?
Bullet class:
public class Bullet extends Actor
{
/**
* Act - do whatever the Bullet wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void hitEnemy()
{
EnemyNormal enemynormal = (EnemyNormal) getOneObjectAtOffset(0, 0, EnemyNormal.class);
if(enemynormal != null)
{
enemynormal.setHealth(-20);
getWorld().removeObject(this);
}
}
public void hitBoss()
{
Boss boss = (Boss) getOneObjectAtOffset(0, 0, Boss.class);
if(boss != null)
{
boss.setHealthBoss(-20);
getWorld().removeObject(this);
}
}
public void act()
{
move(10);
hitEnemy();
hitBoss();
}
}
