So I have an actor that I want to constantly moving to where my main character is moving. So I have two integers that find the X and Y of the "Hero". Then it sets the location of the actor to the Hero. Problem is, when run it, I get an error saying, "Actor not in world. An attempt was made to use the actor's location while it is not in the world." Even though my actor is saved into the world and is visible. Here is the code for the actor that I want to set the location of.
Any idea why it's not working?
import greenfoot.*;
/**
* Write a description of class Invisibru here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Invisibru extends Actor
{
Hero hero = new Hero();
/**
* Act - do whatever the Invisibru wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move();
}
public void move()
{
int X = hero.getX();
int Y = hero.getY();
setLocation(X, Y);
}
}

