Jbox2d simulation runs slowly
31. Květen 2024 v 07:46
I wanted to use jbox2d for my project but I have a issue the physics simulation is running very slowly I tried to change game loops and it did not run any faster the best solution I found is still like half the speed it should be
game loop code (FPS = 60):
double drawInterval = 1000000000/FPS;
double delta = 0;
long lastTime = System.nanoTime();
long currentTime;
while(thread != null) {
currentTime = System.nanoTime();
delta+= (currentTime-lastTime)/drawInterval;
float md = (float) (delta/1000000.0);
lastTime = currentTime;
if(delta >= 1) {
world.step((float)delta ,8,3);
tick(delta);
System.out.println("e");
repaint();
delta--;
}
}