I keep getting this error:
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.
This happens at random, and it's really stressing me out.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class rocks here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class rocks extends Actor
{
/**
* Act - do whatever the rocks wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
setLocation(getX(),getY() + 2);
checkCollision();
if (getY() == 599)
{
getWorld().removeObject(this);
}
}
public void checkCollision()
{
if(isTouching(Xwing.class))
{
Space space= (Space)getWorld();
space.takeHealth(-20);
getWorld().removeObject(this);
}
}
}

