We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

FPS

As it stands, our game is re-drawing the screen as fast as it possibly can. This causes it to use a lot more CPU than it actually needs!

Delta Time

The Greek letter delta (Δ) is often used to represent a change in a value in mathematics. In game development, we use "delta time" to represent the amount of time that has passed since the last frame was drawn. This value is useful to decouple the game's speed from the speed it's being drawn to the screen.

If your computer's CPU speeds up (its speed is not constant, like a sprinter running as fast as they can), the asteroids shouldn't also speed up. Conversely, if your computer slows down, the asteroids shouldn't also slow down: they may just move less smoothly.

Assignment

FPS stands for frames per second. We're going to restrict our game to draw a maximum of 60 times per second, or 60 FPS.

    Use 0.0 instead of 0 because dt will store a decimal number of seconds. Keeping it as a float from the start makes the type hints line up with how we'll use it later.

dt = clock.tick(60) / 1000

If everything is still working as you'd expect, let the game run for a few seconds so that multiple entries are written to game_state.jsonl, run and submit the CLI tests.