Hello, so danpost recently assisted me with getting my health bar onscreen. I would now like to put in a Starting Screen. The first screen, which appears when you start the game, is called "Intro.class" and is supposed to stay there for five seconds, then automatically disappear. This reveals the second screen, "Rules.class" which stays there for 20 seconds. After they're both finished, the Asteroids now start spawning, the Rocket appears, the Counter appears and the Health bar appears. This is what I have for the prepare() method so far (the Rules and Intro picture fill the whole screen, that's why they're in the middle):
In the Intro class (this is the delay, then the removal. I heard that you need to multiply the number of seconds by 60 to get this right?):
In the Rules class (the delay, the removal and the insertion of the other objects):
And I haven't attempted the Asteroid spawning delay yet. I don't think it's as easy as copying and pasting the whole method into the Rules class, so it's still in Space , like this (the delay is my attempt at stopping it from spawning until after the title screens, I don't think it's right):
With all of this, there are no errors, but when I press Run and wait five seconds, a pentagonal turning symbol appears in the bottom right corner, near the classes. When I stop the game, one Asteroid appears (this is because there's no initial delay on the Asteroids spawning, so they'll spawn on the first act method) and an error message appears that says, "NullPointerException", with another red line that says "at Rules.act".
Anyone know how to fix? Thanks in advance.
public void prepare()
{
Rules rules = new Rules();
addObject(new Rules(), 400, 300);
Intro intro = new Intro();
addObject(new Intro(), 400, 300);
// I need to put something to set the location of these two, something like a repeated setLocation? Not a major problem at the moment.
}public void act()
{
Greenfoot.delay(300);
getWorld().removeObject(this);
} private Health healthbar = new Health();
private Counter theCounter;
/**
* Act - do whatever the Rules wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
Greenfoot.delay(1200);
getWorld().removeObject(this);
getWorld().addObject(healthbar,690,34);
Rocket rocket = new Rocket();
getWorld().addObject(new Rocket(270),410,510);
theCounter = new Counter();
getWorld().addObject(theCounter, 76, 30);
} private int delayAsteroid=0;
/**
* Checks the delay of the Asteroid class, and if it's at zero, adds another Asteroid at a
* an x coordinate of 40 degrees, and a random y coordinate.
*/
public void act()
{
Greenfoot.delay(15000);
if (delayAsteroid>0 && --delayAsteroid>0)
{
return;
}
addObject(new Asteroid(), 30, (Greenfoot.getRandomNumber(570)));
delayAsteroid = (Greenfoot.getRandomNumber(60));
}


