DeltaTime

Using Delta Time

In a game, you can do action like move your character every frame. But if you move it with a constant value, it will be faster when you have more fps. To correct that, we have delta time which is the time elapsed since the last frame.

last_tick = current_tick;
current_tick = current_frame // get current frame with your engine or framework
dt = (current_tick-last_tick)/1000.0f;

// dx is the direction (between -1 and 1)
// speed is the amount of pixels you want to travel in 1 second
posX += dx*speed*dt
posY += dy*speed*dt