Is it possible to get a stable framerate?

Hi,

I am working on a game that uses Corona with Box2D.

The problem I’m experiencing is that even when specifying that the framerate should be 30 it seems that this is not the case. I understand that the engine is a best effort approach so if it can’t draw it fast enough the framerate would be below 30 fps, but I am also experiencing burst where the fps will bounce around 30-34 and even having spikes above 60 (the fps is calculated and printed every frame based on current time difference from last frame). Since the physics time steps are bound to the framerate this is causing some trouble.

Is it not possible to set an upper limit on the framerate? Is there a better way to get a steady framerate?

You might be interested in setting the physics engine time step to 1/30, using the physics.setTimeStep API (http://docs.coronalabs.com/api/library/physics/setTimeStep.html).  For me, that’s given the best results when the frame rate isn’t fully constant.

  • Andrew

@aukstudios: Hi. The physics.timestep is set to 30. I should have specified that. The application calculates the physics as if it is to be running in 30 fps when it is in reality running at closer to 33-34 times per second. So every second 3-4 extra timesteps are performed.

So what exactly is the “trouble” that you say is being caused?  I’m not sure I understand what the issue is.

Also, I assume you set the timeStep to 1/30, not 30, right?

  • Andrew

Hi, The problem is that I want to sync on different devices and when one device is running at 30 time steps per second and the other is doing 33 there is a noticeable difference. If it were possible to lock the framerate at 30 they would perform more consistently with each other (provided they are both able to run at 30 fps).

And yes, it is set to 1/30. My bad…

When you say you wan to ‘sync on different devices’, do you mean you want to ensure that a physics simulation with the same initial conditions has the same outcome on two different devices?  Or do you mean you’re making some sort of real-time multiplayer game (where syncing is, naturally, an important consideration)?  Or something else?

  • Andrew

Realtime multiplayer game. There are other things that are being done to make the states similar but locking the framerate would make a lot of sense.

I haven’t worked on a real-time multiplayer game myself, so I might be wrong about this, but I would think that having a completely fixed frame rate across devices wouldn’t necessarily make syncing across devices that much easier.  You’d still have to deal with network latency, and you’d still have to deal with the possibility that the frame rate could sometimes drop.

  • Andrew

You might be interested in setting the physics engine time step to 1/30, using the physics.setTimeStep API (http://docs.coronalabs.com/api/library/physics/setTimeStep.html).  For me, that’s given the best results when the frame rate isn’t fully constant.

  • Andrew

@aukstudios: Hi. The physics.timestep is set to 30. I should have specified that. The application calculates the physics as if it is to be running in 30 fps when it is in reality running at closer to 33-34 times per second. So every second 3-4 extra timesteps are performed.

So what exactly is the “trouble” that you say is being caused?  I’m not sure I understand what the issue is.

Also, I assume you set the timeStep to 1/30, not 30, right?

  • Andrew

Hi, The problem is that I want to sync on different devices and when one device is running at 30 time steps per second and the other is doing 33 there is a noticeable difference. If it were possible to lock the framerate at 30 they would perform more consistently with each other (provided they are both able to run at 30 fps).

And yes, it is set to 1/30. My bad…

When you say you wan to ‘sync on different devices’, do you mean you want to ensure that a physics simulation with the same initial conditions has the same outcome on two different devices?  Or do you mean you’re making some sort of real-time multiplayer game (where syncing is, naturally, an important consideration)?  Or something else?

  • Andrew

Realtime multiplayer game. There are other things that are being done to make the states similar but locking the framerate would make a lot of sense.

I haven’t worked on a real-time multiplayer game myself, so I might be wrong about this, but I would think that having a completely fixed frame rate across devices wouldn’t necessarily make syncing across devices that much easier.  You’d still have to deal with network latency, and you’d still have to deal with the possibility that the frame rate could sometimes drop.

  • Andrew