A real-time game repeatedly samples input, updates the world, and renders the current state. A simple loop is conceptually:
while (running) {
input = readInput();
update(input, deltaSeconds);
render();
}
deltaSeconds is the elapsed time since the previous update. If a player moves at 120 pixels per second, update position by speed * deltaSeconds, not by a fixed number of pixels per frame.
This keeps motion approximately consistent when one machine renders 60 frames per second and another renders 144. Cap unusually large delta values after pauses so one delayed frame does not teleport the player through the level.
Exercises
Trace five frames with delta times of 0.016, 0.016, 0.020, 0.010, and 0.018 seconds.
Calculate how far an object moving at 80 pixels per second travels in 2.5 seconds.
Design separate methods for input, update, and render and state what data each receives.
Self-check
Why should movement use elapsed time?
What are the three main loop phases?
What problem can a very large delta time cause?
Self-Check Quiz
1. What does delta time measure?
(A) Screen resolution
(B) Time since the previous update
(C) Number of players
(D) Memory usage
Answer(B) Delta time is the elapsed time since the previous update.
2. A speed of 100 pixels per second over 0.2 seconds changes position by how much?
Answer20 pixels, calculated as 100 * 0.2.
3. Which phase changes the game world's state?
AnswerThe update phase applies rules, input, physics, and elapsed time to change state.
Homework
Implement a console simulation of one object moving for 10 updates with varying delta times.
Document the state variables, update rule, and one boundary condition.
Explain why a fixed “move 5 pixels per frame” rule behaves differently on different displays.
Sample answer
A correct simulation accumulates position += speed * deltaSeconds. Across updates, total movement should equal speed multiplied by total elapsed time. A strong boundary rule clamps or rejects negative delta values and caps a pause-sized delta to prevent a large teleport.