Workshop › 15 Puzzle › Step 21 of 27
Every frame, update() moves the slide one frame on, and clears it after SLIDE_FRAMES. While a tile is sliding,
other moves wait.
```js
function move(i) {
if (slide) return
// ...
function update() {
if (!slide) return
slide.frame += 1
if (slide.frame >= SLIDE_FRAMES) slide = null
}
function loop() {
update()
draw()
requestAnimationFrame(loop)
}
```if (slide) return in move: while something slides, ignore moves.update does nothing without a slide; otherwise it counts one frame, and at 8 the slide is over (null).move, write if (slide) return as the first line.function squareX(i), write update and leave an empty line.loop, write update() above draw(). Press Run.Skills: The game loop, Game states
← Remember the slide Smooth sliding →