-
-
Save melcor76/5d76fa4898106917c0e5b11874b54dab to your computer and use it in GitHub Desktop.
js-tetris - animate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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