What do you mean with 'it doesn't work'?
What I think would happen is that you create so many actors that the scenario visually stops because it is very slow due to all the actors.
addObject(new NameOfTheClass(),Greenfoot.getRandomNumber(getWidth()),Greenfoot.getRandomNumber(getHeight()));
addObject(new NameOfTheClass(),Greenfoot.getRandomNumber(2)*getWidth(),Greenfoot.getRandomNumber(2)*getHeight());
addObject(new NameOfTheClass(),Greenfoot.getRandomNumber(getWidth()),Greenfoot.getRandomNumber(getHeight()));
addObject(new NameOfTheClass(),Greenfoot.getRandomNumber(2)*getWidth(),Greenfoot.getRandomNumber(2)*getHeight());
int[] x = {x1,x2,x3,...}
int[] y = {y1,y2,y3,...}
double chance = 0.01 // for a 1/100
public void act() {
if(Math.random() < chance) {
addObject(new NameOfTheClass(),x[Greenfoot.getRandomNumber(x.length)],y[Greenfoot.getRandomNumber(y.length)]);
}
}addObject(new NameOfTheClass(),Greenfoot.getRandomNumber(getWidth()),Greenfoot.getRandomNumber(getHeight()));
addObject(new NameOfTheClass(),Greenfoot.getRandomNumber(2)*getWidth(),Greenfoot.getRandomNumber(2)*getHeight());
int[] x = {x1,x2,x3,...}
int[] y = {y1,y2,y3,...}
double chance = 0.01 // for a 1/100
public void act() {
if(Math.random() < chance) {
addObject(new NameOfTheClass(),x[Greenfoot.getRandomNumber(x.length)],y[Greenfoot.getRandomNumber(y.length)]);
}
}import greenfoot.*;
public class enemy1 extends objects
{
public void act()
{
Whentospawn();
setLocation(getX(), getY() - 1);
}
public void Whentospawn()
{
if (Greenfoot.getRandomNumber(2) == 1)
{
}
}
}import greenfoot.*;
public class Spawner extends objects
{
public void act()
{
spawn();
}
public void spawn()
{
if (Greenfoot.getRandomNumber(1) == 0) //every act
{
getWorld().addObject(new enemy1(), getX(),getY());
}
}
}turnTowards(getWorld().getWidth()/2,getWorld().getHeight()/2); // turnTowards the centre move(<speed>)
enemy1.Whentospawn(); enemy2.Whentospawn(); // etc.
enemy1.Whentospawn(); enemy2.Whentospawn(); // etc.