Chapter 20 — Game Loop, FPS and Delta Time
Part 2A — 2D Game Fundamentals · Chapter 20 of 62 · 6 h
Chapter 20 — Game Loop, FPS and Delta Time
Level: intermediate Estimated time: 6 h Prerequisites: chapter 19 — Flutter crash course for games (
runApp,StatefulWidget,setState,Ticker,CustomPainter) What you will be able to do by the end: write a complete game loop in Dart and pure Flutter, measure FPS, and make an object move at the same real speed on every machine thanks to delta time.
20.0 — Chapter objectives
By the end of this chapter, you will be able to:
- explain what technically sets a game apart from a classic application;
- describe the input → update → render pattern and redraw it from memory;
- write a first game loop in console Dart;
- explain why a
while (true)freezes a Flutter application; - define a frame and a frame rate (frames per second, FPS);
- convert a number of FPS into a frame duration in milliseconds, and back;
- demonstrate the bug of a movement written as
x += 5per frame; - define delta time and write
x += vitesse * dt; - reason in pixels per second rather than pixels per frame;
- compute a
dtfrom aStopwatch; - use a
TickerandSchedulerBindingto drive a Flutter loop; - display an FPS counter and smooth it with a moving average;
- recognise an abnormal
dtafter a lag spike and cap it withclamp; - implement a fixed timestep with an accumulator;
- compare fixed and variable timesteps and choose with full knowledge;
- decouple update from rendering and interpolate between two states;
- pause the game, slow it down or speed it up with a time factor;
- name precisely what the Flame engine will do for you from chapter 27 onwards;
- assemble a small reusable loop engine for all the following chapters.
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion