Workshop › 2048 › Step 25 of 26
If the finger barely moved (less than 30 pixels either way), it was a tap, not a swipe. A tap does what Space does: go on after a win or a game over.
```js
if (Math.max(Math.abs(dx), Math.abs(dy)) < 30) next() // too short for a swipe: a tap
else if (Math.abs(dx) > Math.abs(dy)) move(dx > 0 ? 'right' : 'left')
// Space, Enter or a tap: start again after game over, or keep playing after a win.
function next() {
ctx.fillText(state === 'won' ? 'Space or tap to keep going' : 'Space or tap to try again', canvas.width / 2, TOP + 220)
```Math.max(...) is the bigger of the two distances; under 30 pixels it is a tap and calls next(). The swipe line
becomes else if.next gets a comment, and the screens now mention the tap.pointerup listener, write the tap line above the if line, and make that line else if.function next() { write the comment.'Space or tap to keep going' and 'Space or tap to try again'.Skills: Keyboard and mouse input
← Swipes Build it yourself: undo →