Skip to content

Instantly share code, notes, and snippets.

@melcor76

melcor76/main.js Secret

Created November 19, 2019 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melcor76/5d76fa4898106917c0e5b11874b54dab to your computer and use it in GitHub Desktop.
Save melcor76/5d76fa4898106917c0e5b11874b54dab to your computer and use it in GitHub Desktop.
js-tetris - animate
function animate(now = 0) {
// Update elapsed time.
time.elapsed = now - time.start;
// If elapsed time has passed time for current level
if (time.elapsed > time.level) {
// Restart counting from now
time.start = now;
this.drop();
}
// Clear board before drawing new state.
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
board.draw();
requestId = requestAnimationFrame(animate);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment