The problem is from where you are calling the method from. It needs to be in an act method -- not in the constructor of the world.
public void act()
{
CheckNextLeveL();
}public void act()
{
CheckNextLeveL();
}// Level1 code Greenfoot.setWorld(new Shop(PlayerNumber, new Level2()));
// Shop code
// instance field
private World gotoWorld;
public class Shop(int PlayerNumber, World world)
{
gotoWorld = world;
// etc.public World getNextWorld()
{
return gotoWorld;
}Greenfoot.setWorld(((Shop)getWorld()).getNextWorld());
// Shop code
// instance field
private World gotoWorld;
public class Shop(int PlayerNumber, World world)
{
gotoWorld = world;
// etc.public World getNextWorld()
{
return gotoWorld;
}// Level1 code Greenfoot.setWorld(new Shop(PlayerNumber, new Level2()));
// Level1 code Greenfoot.setWorld(new Shop(PlayerNumber, new Level2()));
int changes = 0;
int actorCount = getObjects(ClassA.class).size();
while (actorCount > 0 && changes < 10)
{
Actor actor = (Actor)getObjects(ClassA.class).get(Greenfoot.getRandomNumber(actorCount));
addObject(new ClassB(), actor.getX(), actor.getY());
removeObject(actor);
actorCount--;
changes++;
}public static int ActivateGhost = 0;
private int ActTimer = 0;
int changes = 0;
int actorCount = getWorld().getObjects(Point1.class).size();
public void act()
{
ActTimer++;
if (ActTimer == 40)
{
if (ActivateGhost == 0)
{
ActivateGhost = 1;
}
else
{
ActivateGhost = 0;
}
ActTimer = 0;
}
if (ActivateGhost == 1)
{
while (actorCount > 0 && changes < 10)
{
Point1 actor = (Point1)getWorld().getObjects(Point1.class).get(Greenfoot.getRandomNumber(actorCount));
getWorld().addObject(new Ghost1(), actor.getX(), actor.getY());
getWorld().removeObject(actor);
actorCount--;
changes++;
}
ActTimer++;
}
else
{
while (actorCount > 0 && changes < 10)
{
Ghost1 actor = (Ghost1)getWorld().getObjects(Ghost1.class).get(Greenfoot.getRandomNumber(actorCount));
getWorld().addObject(new Point1(), actor.getX(), actor.getY());
getWorld().removeObject(actor);
actorCount--;
changes++;
}
}