Workshop › Rhythm Lanes › Step 16 of 35
Nobody presses at exactly the right frame, so a hit needs a window: a press counts if the note's time is within
GOOD (9) frames of now, a little early or a little late. Otherwise nothing happens and the note keeps coming.
```js
const GOOD = 9
// A key press hits the closest note in its lane, if it is close enough in time.
function press(lane) {
if (!closest) return
const off = Math.abs(closest.time - frame)
if (off > GOOD) return // too early: nothing happens, and the note is still there
closest.hit = true
```off is how many frames the press is away from the note's time.if (off > GOOD) return leaves press before the note is marked, so a press far too early does nothing.LEAD write GOOD (above KEYS).function press(lane) { write the comment.press, between if (!closest) return and closest.hit = true, write the two new lines.Skills: Game states
← Hit the closest note One press, one hit →