Hello, I am currently coding a program where obstacles periodically appear and cross a map. However, I want these obstacles to disappear one by one once they reach the map edge. But when I put in the code for this, I get a NullPointerException after about three objects are spawned. Can anyone help me? Thank you!
public void act()
{
slide();
spawn();
}
public void slide()
{
if (!(getX()==0))
{
setLocation(getX()-3, getY());
}
else
{
Actor ob = getOneObjectAtOffset(0, 0, Obstacle1.class);
getWorld().removeObject(ob);
getWorld().removeObject(this);
}
}
public void spawn()
{
spawnCounter++;
if (spawnCounter == 200)
{
spawnCounter = 0;
getWorld().addObject(new Obstacle1(), 780, 470);
}
}
