I have just finished to develop my vertical scrolling game for android using libgdx and box2d. Everything worked fine till I implemented the handling of the game state (pause, resume,running,game over). I followed the example of superjumper and it works. Here is my code where I update the state:
@Override
public void update(float deltaTime) {
switch (state) {
case GAME_RUNNING:
assetsLoader.update(deltaTime, world);
world.step(deltaTime, 12,6);
updateRunning();
break;
case GAME_PAUSED:
world.step(0, 12, 6);
updatePaused();
break;
}
}
And here there is the function draw that I call in my render method:
public void draw(){
switch (state) {
case GAME_RUNNING:
presentRunning();
break;
case GAME_PAUSED:
presentPaused();
break;
case GAME_OVER:
presentGameOver();
break;
}
}
Now the problem is that when I start the game I experiment a lot of lag (my fps are around 59-61) and my bodies(I have got only 10 of them and they move with a linear velocity that never changes) start to stutter. I have already set restitution to 0 but nothing changed so I think that the problem is inside the switch state probably because it slows down the performance of my game also because before I implemented this part I didn't experience these problems.
Is it possible to manage the game states in another way?
switch? To me it sounds like your state is wrong sometimes and therefore the bodies don't move for some frames, causing the stuttering. - Robert P