Why requestAnimationFrame() does not work in my canvas java script | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

Why requestAnimationFrame() does not work in my canvas java script

14th Jun 2021, 3:15 PM
Taha Khan
Taha Khan - avatar
7 Answers
+ 6
Could you share your code snippet here? Meanwhile, this is a demo about requestAnimationFrame https://code.sololearn.com/Wdjwm2m4P4iV/?ref=app
14th Jun 2021, 3:32 PM
Gordon
Gordon - avatar
+ 7
Gordon unfortunatelly if you click the button restart several times behind the speed increases with every click, which is quite annoying. Can you fix that?
14th Jun 2021, 4:57 PM
JaScript
JaScript - avatar
+ 6
Very good Artur thanks.
15th Jun 2021, 4:16 PM
JaScript
JaScript - avatar
+ 5
Thanks for answering my question
14th Jun 2021, 3:37 PM
Taha Khan
Taha Khan - avatar
+ 4
JaScript requestAnimationFrame returns a value (long numeric id). Just check if callback returned any value in variable "raf". If so, don't request another frame. If not, then kick it to start
15th Jun 2021, 2:06 PM
Artur
Artur - avatar
15th Jun 2021, 2:06 PM
Artur
Artur - avatar
+ 4
JaScript You're welcome 🤗
15th Jun 2021, 7:55 PM
Artur
Artur - avatar