LibGDX timer doesn't start after resuming game on Android
I am creating 2 timers in my code. One of them is a boolean timer that updates the logic every 0.017 seconds:
logicTimer = new Timer();
logicTimer.scheduleTask(new Timer.Task() {
@Override
public void run() {
updateLogic();
}
}, 0f, timePerProcessing);
And the other is to create obstacles every 3 seconds:
meteoroidTimer = new Timer();
meteoroidTimer.scheduleTask(new Timer.Task() {
@Override
public void run() {
generateMeteoroids();
}
},1f,3f);
When I pause my game and resume afterwards, my logic timer still works, but my obstacle timer doesn't work. I thought it was because I am using a random object in my method that I call on the timer, but I tried with a simple one:
System.out.println("It is showing");
and it still doesn't renew.
My code for pause and resume:
@Override
public void pause(){
meteoroidTimer.stop();
logicTimer.stop();
}
@Override
public void resume(){
meteoroidTimer.start();
logicTimer.start();
}
+3
source to share