Workshop › Flappy-style Bird › Step 22 of 30
Show the score
What we are doing
The score is drawn as a big white number, centered near the top. fillText wants text, so String(score) turns the
number into text.
```js
ctx.textAlign = 'center'
ctx.font = 'bold 40px sans-serif'
ctx.fillText(String(score), canvas.width / 2, 70)
```
What it means
- The color (
white) and centering come from the two lines above.
String(7) is '7': fillText writes text.
- (200, 70) is the middle, 70 pixels from the top.
Your turn
In draw, under ctx.textAlign = 'center', write the two lines.
Skills: Drawing on a canvas
← Score each pipe once A function for a fresh start →
All steps
- Get the canvas and the pen
- Paint the sky
- Draw the bird
- A function that draws
- A function that moves
- The game loop
- Gravity
- A flap
- Space, Up arrow or a tap
- Wait for the first flap
- The ground and the sky
- Tell the player
- A pipe as data
- Draw the pipes
- The world moves, not the bird
- A new pipe at a random height
- A pipe every 90 frames
- Remove the pipes you passed
- Is the bird level with a pipe?
- Through the opening
- Score each pipe once
- Show the score
- A function for a fresh start
- Try again
- One place where the game ends
- Remember the best score
- Show the best score
- The same speed on every screen
- No catching up after a pause
- Build it yourself: a medal