Why do you want to keep track of them?


stars[i] = new Star(); addObject(stars[i], x, y);
import greenfoot.*; import java.awt.Color; public class SpaceWorld extends World { final int starCount = 300; Star[] stars = new Star[starCount]; public SpaceWorld() { super(600, 400, 1); createBackgroundImage(); createStars(); } public void createBackgroundImage() { getBackground().setColor(Color.BLACK); getBackground().fill(); } public void createStars() { for (int i = 0; i < starCount; i++) { int x = Greenfoot.getRandomNumber(getWidth()); int y = Greenfoot.getRandomNumber(getHeight()); stars[i] = new Star(); addObject( stars[i], x, y); } } }
import greenfoot.*; import java.awt.Color; public class SpaceWorld extends World { final int starCount = 300; Star[] stars = new Star[starCount]; public SpaceWorld() { super(600, 400, 1); createBackgroundImage(); createStars(); } public void createBackgroundImage() { getBackground().setColor(Color.BLACK); getBackground().fill(); } public void createStars() { for (int i = 0; i < starCount; i++) { stars[i] = new Star(); addObject( stars[i], getWidth(), getHeight()); int x = Greenfoot.getRandomNumber(getWidth()); int y = Greenfoot.getRandomNumber(getHeight()); } } }
public void createStars() { for (int i = 0; i < starCount; i++) { int x = Greenfoot.getRandomNumber(getWidth()); int y = Greenfoot.getRandomNumber(getHeight()); stars[i] = new Star(); addObject( stars[i], x, y); } }
int r = Greenfoot.getRandomNumber(256); // red int g = Greenfoot.getRandomNumber(256); // green int b = Greenfoot.getRandomNumber(256); // blue img.setColor(new Color(r, g, b));