Workshop › Tetris-style Blocks › Step 29 of 32
We always draw one piece ahead and keep it in next, so the player can plan. spawn uses next and draws a new one;
the panel shows it.
```js
let next
next = takeFromBag()
spawn()
const shape = next
next = takeFromBag()
ctx.fillText('Next', panel, 30)
drawShape(next, 11, 2)
ctx.fillStyle = 'white' // drawShape changed the fill color; the labels below need white again
```newGame draws the first next before the first spawn.spawn turns next into the falling piece and draws a new next.next at column 11, row 2 (in the panel, since the well has columns 0–9).drawShape changes fillStyle, so we set it back to white for the labels below.let piece write let next.newGame, above spawn(), write next = takeFromBag().spawn, replace const shape = takeFromBag() with the two lines.draw, under ctx.textAlign = 'left', write the three Next lines.Skills: Game states, Drawing on a canvas
← A fair bag of pieces Drop it →