Skip to content
Advertisement

Canvas and JavaScript – Flowing word from right to left while waiting for keypress input

I’m new and I am trying to write my first program. In this snippet I try to flow a word from right to left and on the left move a bar to the right and when they collide a life will be taken. I also have a keypress event that strips the word of its corresponding character. The problem is that the animation goes too fast. There is no time to listen for input and give score. I have tried with setTimeout and SetInterval but they dont work. Thanks a bunch!

JavaScript
JavaScript

Advertisement

Answer

You can use a callback like setInterval() or requestanimationframe() to draw each frame sequentially. Here’s a simple example that only modifies your code slightly. You should research the topic to understand more fully.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement