开发者

HTML5 animation in canvas

开发者 https://www.devze.com 2023-03-26 23:25 出处:网络
Is there other ways to animate an object moving in a canvas without the use of setInterval() or setTimeout()?

Is there other ways to animate an object moving in a canvas without the use of setInterval() or setTimeout()?

Reason is because it kinda lags as time goes by when using useInterval(). I got no idea why it lags also.

开发者_C百科I tried removing the setInerval() and everything is ok with no lag but there is no animation.


Does anyone know if there is other ways to animate an object moving in a canvas without the use of setInterval() or setTimeout().

Yes. There is also requestAnimationFrame, but not on all browsers.

Additionally, try setting your interval to much smaller and much larger values and see if either make it less jumpy.

Additionally, make sure there is as little going on in your draw loop. It could be your own fault for the lag. Canvas is pretty sensitive to performance things, and its up to you to keep it running fast.


Define lag, do you mean kinda jumpy? because if so your set interval is wrong, I have animated plenty of canvas using those two methods, and afaik there is no other way.

0

精彩评论

暂无评论...
验证码 换一张
取 消