Getting consistent speed with JBox2d app

Hi all,

I’ve just been messing about with JBox2D, and it seems pretty great. The only problem I have is getting an app to run at a constant speed when run on different PCs. It runs fine on a fast PC, but slow on a slower PC. Do I need to throttle the game loop like you would in any other game, or does it do that automatically? E.g. is the following okay:-

 while (true) {
            world.step(timeStep, velocityIterations, positionIterations);
 }

or should it be more like:

 while (true) {
            world.step(timeStep, velocityIterations, positionIterations);
            Thread.sleep(1000/fps);
 }

And do I need to tweak the params I’m passing to World.step(), ie. timeStep, velocityIterations, and positionIterations, for better performance?

Thanks in advance!

EDIT: By looking at the testbed examples, I’ve seen that the latter is correct. However, my own app seems to run very slow. I’ve got a gravity of (0, -10) and I’ve created a ball with a density of 10,000. However, it still takes about 10 seconds to drop 600.

When I had been playing around with box2d, that was around the point where I had to go through the process of doing the “fix your timestep” thing…

The only other thing that I could think of (keep in mind of limited experience), perhaps the scale is not being set properly? That was one of the first issues I came across when playing with box2d was ensuring that the scale was adequate… although, if the results are normal on a faster computer, this might not be the right solution, but it could be the factor of each pixel being treated as 1meter.

I think you’re right, I just need to tweak the values; although I’ve just realised I made a real n00b mistake and forgot that all objects fall at the same speed regardless of weight. Doh!