Hey it's me again!
I have one more problem with my game. So when the player clicks on start, the first two balls don't appear right away, only after ten seconds. Ten seconds later, two more balls appear and so on. My problem is that ten seconds without any ball at the beginning is too much, but we don't want the first balls to appear just when the player has clicked start, but like 3 or 5 seconds later. I have done something that kinda works, but it delays everything from 5 seconds, so that means the timer appears only after this time, the start button disappear also only after. I want the timer to start and the start button to disappear and THEN wait 5 seconds and then the balls appear.
Here is my code for Background:
public class Background extends World
{
Start start = new Start();
Help help = new Help();
Title title = new Title();
Timer timer = new Timer();
boolean isRunning;
public void act(){
if (Greenfoot.mouseClicked(start)){
removeObject(title);
removeObject(start);
removeObject(help);
startGame(); }
if (isRunning){
runBallSpawnTimer(); }
if(getObjects(Player1.class).isEmpty()){
endGame(); }
setActOrder(Ground.class);
}
public void startGame(){
this.addObject(timer, 300, 10);
isRunning = true; }
boolean empty = true;
int BallSpawnTimer1;
int BallSpawnTimer;
int b = 0;
int a = 0;
long moveDelay;
private void runBallSpawnTimer(){
BallSpawnTimer = (BallSpawnTimer + 1)%500;
if (a == 0){
moveDelay = System.currentTimeMillis();
a = 1;
}
while(empty == true && b == 0){
if(System.currentTimeMillis() - moveDelay == 5000){
spawnBall();
b = 1;
}
}
if (BallSpawnTimer == 0 ) {
if (!getObjects(Ball.class).isEmpty() /*|| empty == true*/){
spawnBall();
}
empty = false;
}
}
}

