60 frames per second

Play this lesson

A game is a flipbook

Have you ever drawn a flipbook? Each page is a still picture, but flip fast and the drawing moves.

Games work the same way. Each still picture is called a frame. The game draws frame after frame so fast that your eyes see smooth motion.

60 frames per second

FPS means frames per second. Our goal is 60 FPS. One second is 1,000 milliseconds, and 1,000 divided by 60 is about 16.7 milliseconds per frame.

That is the frame budget. In that tiny time, the game must read your buttons, move every ship and bullet, check for hits, update the score and draw the whole picture. Then it starts again. Sixty times, every second.

Bolt says: Many phones now refresh 120 times a second. To keep up, the budget shrinks to just 8.3 milliseconds per frame.

Quick check

At 60 FPS, about how long does the game have to make each frame?

  1. About 16.7 milliseconds
  2. About 1 second
  3. About 60 milliseconds
Show the answer

About 16.7 milliseconds

1,000 milliseconds divided by 60 frames is about 16.7 milliseconds. Everything for one frame has to fit in that time.

When frames run late

Imagine a huge wave in Hyper Shards: 300 bullets, 50 aliens and thousands of sparks. Now one frame takes 33 milliseconds instead of 16.7, so the game drops to 30 FPS.

Movement looks jumpy and the controls feel slow, because your press waits longer to show up. Players call this lag. Even one slow frame now and then shows up as a visible hitch, called a stutter.

Effects cost work too. Every spark is a small object that must be moved and drawn, so effects need limits.

Two kinds of workers

Canvas, WebGL and PixiJS

Bolt says: WebGL with PixiJS is in the studio's original plan for Hyper Shards, so its big effects can stay at 60 FPS.

Quick check

Hyper Shards needs to draw 5,000 sparks every frame. Why does PixiJS help?

  1. It uses WebGL to hand the drawing to the GPU, thousands of painters at once
  2. It makes the CPU do all the drawing, one spark after another
  3. It stores the sparks in the cloud
Show the answer

It uses WebGL to hand the drawing to the GPU, thousands of painters at once

PixiJS is a library that talks to the GPU through WebGL for us. Drawing lots of things at once is exactly what the GPU is built for.

Object pooling: reuse, don't throw away

Hyper Shards fires lots of bullets. If the game makes a brand new bullet for every shot and throws it away when it leaves the screen, the computer piles up junk. Every so often it stops to clean up, which is called garbage collection, and the game stutters.

Object pooling fixes this. We make 100 bullets at the start and keep them in a pool. When a bullet flies off screen, it goes back in the pool, ready to be fired again.

Bolt says: It is like a bowling alley lending the same shoes again and again, instead of buying new ones for every game.

Frame budget

frame-timings.txt
// Hyper Shards, wave 9: one frame (ms)readInput      0.2moveShips      1.1checkHits      2.4updateSparks  14.0   // 5,000 sparksdrawScreen     6.3------------------total         24.0   // budget: 16.7

Wave 9 runs at about 40 FPS. Which change brings Hyper Shards back to 60 FPS?

  1. Cap the sparks at 1,000 on screen, reused from a pool
  2. Make reading input faster
  3. Add more sparks so the motion looks smoother
  4. Play a louder explosion sound
Show the answer

Cap the sparks at 1,000 on screen, reused from a pool

Sparks use 14 of the 24 ms. A fifth as many sparks takes about 2.8 ms, so the frame drops to about 12.8 ms, inside the 16.7 ms budget. Input only takes 0.2 ms, so speeding it up can't save enough.

Measure, don't guess

Before fixing a slow game, find out what is slow. Browsers have built-in developer tools with a Performance panel that records frames and shows which code took the time, like the wave 9 timings.

Test on a cheap, older phone, not only a fast laptop. Phones also slow themselves down when they get hot, which is called thermal throttling, so play for ten minutes, not just one.

Bolt says: Next lesson: art, sprites and animation, and why sprite size matters for frames too.

Fact-checked 9 October 2026