Hello,
I have a if condition that when the start button is clicked, some things of my code have to start. I also wanted to start the timer which is spawning the balls as soon as I click the start button. But if I put it into the condition, it doesn't work. Here the code:
Whether I put runBallSpawnTimer() in the if condition or in the startGame() method, none of them make it work. As soon as I put the runBallSpawnTimer() outside of the if like this:
It works but well the code is being executed before I pressed start.
Thanks for the help! :)
public void act(){
if (Greenfoot.mouseClicked(start)){
startGame();
runBallSpawnTimer();
}
}
public void startGame(){
Timer timer = new Timer();
this.addObject(timer, 300, 10);
}
boolean empty = true;
int BallSpawnTimer;
private void runBallSpawnTimer(){
BallSpawnTimer = (BallSpawnTimer+1)%1500;
if (BallSpawnTimer == 0) {
if (!getObjects(Ball.class).isEmpty() || empty == true){
spawnBall();
}
empty = false;
}
}public void act(){
if (Greenfoot.mouseClicked(start)){
startGame();
}
runBallSpawnTimer();
}
