The terminal window keeps opening and it states that "Actor not in world. An attempt was made to use the actor's location while it in not on the world....."
I'm trying to remove an object when another object touches it and that keeps popping up.
public void act()
{
setLocation(getX(), getY()-2);
if (getY() == 0)
{
getWorld().removeObject(this);
}
}
public void checkCollission()
{
if (isTouching(Bear.class))
{
getWorld().removeObject(this);
}
}
} public void act()
{
checkKeyPress();// Add your action code here.
if(!isTouching(Pizza.class))
{
setLocation(getX(),getY()+2);
}
}
private void checkKeyPress()
{
if (Greenfoot.isKeyDown("left"))
{
setLocation(getX()-4, getY());
}
if (Greenfoot.isKeyDown("right"))
{
setLocation(getX()+4, getY());
}
if (Greenfoot.isKeyDown("space") && !pressed)
{
setLocation ( getX(), getY()+vSpeed);
vSpeed = vSpeed + acceleration;
pressed = true;
}
if (!Greenfoot.isKeyDown("space") && pressed)
{
pressed = false;
}
}
public void jump()
{
vSpeed = -16;
}
public void checkCollission()
{
if (isTouching(Bear.class))
{
removeTouching(Pizza.class);
}
}public MyWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
Bear bear = new Bear();
addObject(bear, 50, 73);
Pizza pizza = new Pizza();
addObject(new Pizza(),Greenfoot.getRandomNumber(600), 350);
}
public void act()
{
if (Greenfoot.getRandomNumber(100) < 3)
{
addObject(new Pizza(),Greenfoot.getRandomNumber(600), 350);
}
}
}