Workshop › Breakout › Step 28 of 39
Lives and a hint on screen
What we are doing
The player should see how many lives are left and, while serving, how to launch. Canvas draws text with fillText.
```js
ctx.fillStyle = 'white'
ctx.font = '16px sans-serif'
ctx.textAlign = 'left'
ctx.fillText('Lives: ' + lives, 10, 26)
ctx.textAlign = 'center'
if (state === 'serve') ctx.fillText('Click or press Space to launch', canvas.width / 2, 260)
```
What it means
font sets the size and typeface; textAlign says whether the point is the text's left end or its center.
'Lives: ' + lives joins text and a number: 'Lives: 3'.
fillText(text, x, y) paints the text at that point. The hint is drawn only while serving.
Your turn
In draw, under the ball's ctx.fill() line, leave an empty line and write the text lines.
Skills: Drawing on a canvas
← Three lives Game over →
All steps
- The field and the paddle
- Draw again and again
- Keep a number inside limits
- Follow the mouse
- A canvas shown at another size
- A ball with a velocity
- Draw a round ball
- Move the ball
- Bounce off the side walls
- Bounce off the ceiling
- The open floor
- Bounce off the paddle
- Aim with the paddle
- A row of bricks
- Draw the bricks
- A whole wall: a loop inside a loop
- A color for every row
- Circle meets box
- Break a brick
- Hitting the side of a brick
- Wait on the paddle
- Ride along with the paddle
- Launch the ball
- Click or press Space
- Remember which keys are held
- Steer with the arrow keys
- Three lives
- Lives and a hint on screen
- Game over
- Keep score
- Show the score
- Win the game
- One function for a new game
- Play again
- A burst of particles
- Break into sparks
- Move, fall and disappear
- Fade out
- Build it yourself: tough bricks