So i recently started programming, so i am kind of a noob. I am making a game for school where i have a cannon, shooting objects at 2 ships which needs to be destroyed when the bullet hits them.
This is my code for my bullet:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class kogel here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class kogel extends Mover
{
private int life = Greenfoot.getRandomNumber(10) + 20;
/**
* Act - do whatever the kogel wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(10.0);
life--;
if (life ==0)
{
getWorld().addObject(new explosie(), getX(), getY());
getWorld().removeObject(this);
}
Actor schip;
schip = getOneObjectAtOffset(0, 0, schip.class);
if (schip !=null)
{
getWorld().removeObject(schip);
}
}
}
I get an error "Actor not in world", however the ships disappears as it should so i dont understand why its giving me this error while the game is actually just working fine..
