Reputation: 31
I'm trying to draw a figure on canvas, and the calls to the canvas are inside the while loop. The issue is that the results are not shown (drawn) on canvas until the whole loop is done. The code example is attached. If unclear I can post the entire code.
while (remainingLetters > 0 && numOfTries > 0) {
z++;
ctx.fillRect(10*z,10*z, 50, 50);
}
My expected result is that this will draw one rectangle each time it loops, and will offset it in x and y direction by 10 pixels. That does happen indeed, but only after the loop is done, how I know this, is because this is a hangman game and it has some other check and calls to prompt() and alert() functions. These shapes are drawn only after the game (while loop) ends.
Upvotes: 1
Views: 104
Reputation: 1512
Don't really know much about the canvas but have you tried with setinterval() instead of while(), or maybe requestAnimationFrame()
Upvotes: 1