Controlling Speed on different systems


Long time troll, first time poster!

My problem is that I started making a game whereby balls bounce around within some walls. Today I reformatted my laptop due to vista killing it and decided to take the plunge to ubuntu. I have now got a serious performance boost and now my balls look like they are on caffeine!

This made me think, if I run this code on an older machine it will seem incredibly slow and vice versa.

This is what I think the solution should be but I'm not sure how to implement it: update the balls ever X milliseconds.

Any idea on how to do this or is there a better way?


Move the objects depending on the time per frame. (multiply with the time per frame which is usually passed to the update() method)

The more frames per second you got, the less you need to move the objects per frame.

surely if the FPS is high, multiplying numbers by the FPS would then be going even faster depending on the computer setup?

sorry being a noob.

here is a bit of code that is called inside the update method that seems to work.

time = new Date();
timeNow = time.getTime();
if((timeNow - timeOld) > 5){
   timeOld = time.getTime();

Would the FPS way be more reliable than this?

Oh I get it now, not FPS but time per frame…

I'm whipping something up now :smiley:

right :slight_smile:

you can look at BaseSimpleGame to see how ‘Timer timer’ is used to get the tpf.