Workshop › Rhythm Lanes › Step 34 of 35
On a phone the lanes themselves become the buttons: a tap anywhere in a lane presses it, through the same press.
After the song, a tap plays again.
```js
// On a touch screen, each lane is its own big button.
canvas.addEventListener('pointerdown', (event) => {
if (state === 'done') return reset()
const rect = canvas.getBoundingClientRect()
const x = ((event.clientX - rect.left) * canvas.width) / rect.width
const lane = Math.floor((x - LEFT) / LANE_W)
if (lane >= 0 && lane < LANES) press(lane)
})
ctx.fillText('Space or tap to play again', canvas.width / 2, 318)
```pointerdown fires for a mouse button or a finger going down on the canvas.getBoundingClientRect() gives the canvas's box on the screen; the formula turns the page position into canvas
pixels, even when the canvas is shown smaller on a phone.Math.floor((x - LEFT) / LANE_W) is the lane under the tap; outside 0 to 3 nothing happens.function draw() { write the comment and the pointerdown listener, with an empty line after it.'Space or tap to play again'.Skills: Keyboard and mouse input
← Best score Build it yourself: a speed setting →