Workshop › Missile Command-style Defense › Step 13 of 35
A click (or tap) on the canvas fires at that point. The page position is converted to canvas pixels, even when the canvas is shown at another size.
```js
canvas.addEventListener('pointerdown', (event) => {
const rect = canvas.getBoundingClientRect()
fire(((event.clientX - rect.left) * canvas.width) / rect.width, ((event.clientY - rect.top) * canvas.height) / rect.height)
})
```pointerdown fires when the canvas is clicked or touched.rect is the box the canvas is shown in. event.clientX - rect.left is the distance from its left edge.canvas.width and dividing by rect.width fixes the scale when the canvas is shown bigger or smaller.Write the listener above the // Move a point ... comment, followed by an empty line.
Skills: Keyboard and mouse input
← Fire an interceptor Interceptors fly →