Question

Say like it took a whole second for a character to jump in a game, how would a game developer go about keeping that jump time to 1 second if the FPS is either 10fps, 30fps, 100fps etc? - If you get me, how would you stop a game's fps affecting the gameplay speed basically.

I presume there's a certain method of doing this, so I was wondering what exactly it is?

Thankssss, Alex!

Was it helpful?

Solution

Normally by using a timer to record how much time has passed since the last frame was rendered. There are many articles and samples on the subject available via Google:

Of course if your FPS is allowed to be anything then you will end up with unrealistic simulations. For this reason there is the concept of a "fixed time step".

The "Fix Your Timestep!" (and the previous articles linked on that page) in particular is a good read on this subject.

OTHER TIPS

Short answer of a large subject
I guess your game should place "animation" not determine by its frame sequences number but by the time delay from a reference...

1)example : 1 second jump with only 3 drawing ... should be considere draw#1 a t0 draw#2 if between t+0.25 and t+0.75 and draw#3 if between t+0.75 and t+1

2) example : if your move/animation is determined by a formula like positionX(int RelativeFrameNumber) your should consider change your fonction by using time like positionX(long relativeTimeInMillisecond)

or with small change in your gameloop
3) place a "wait" code in your loop that is calibrate depending a continuously/fixed computed framerate performance

Hope that help

Many physics engines pass around a delta time in an update() method of some kind.

void update(float dt)

This delta value represents the current frame step proportional to a fixed frame rate (say, 60fps). For example, if dt is 1.0, then we're at 60fps, if dt is 2.0, then we're 30fps and if dt is 0.5 then we are at 120fps.. etc..

To move (in your case, jump) a character at the same speed for any frame rate, multiply dt by the object's velocity vector to keep the character jumping at the same speed.

void update(float dt)
{
    myChar.Vel += myChar.Direction.Normalized() * myChar.Speed * dt;
    //myChar.Speed is in meters per second    
}

Note: Different calculation is required for quadratic physics.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top