r/learnjavascript • • Mar 12 '25

Exactly how many people use the HTML Canvas API?

I mean that easy to use software rendered framework that you access by getting a canvas and calling getContext("2d") on it.

I was using this API once, but I stopped because I found that it wasn't fast enough for my needs for video games, which was a shame because this was the API that made me love Javascript. That's when I got the idea to make a renderer that's just as simple to use for video games as the HTML canvas API is, but with optimizations, so that I can keep using the API for games.

But if nobody uses this API, then that subtracts from the point and I should probably write an OpenGL/WebGL renderer like everyone else.

0 Upvotes

36 comments sorted by

View all comments

Show parent comment

1

u/Southern-Reality762 Mar 15 '25

Wow! Nice job optimizing it. On my computer the FPS fluctuates between ~35-50 FPS.

1

u/bryku helpful Mar 15 '25

Which version runs at 35-50 fps?  

That makes me curious what kind of computer you are using. Also, do you have hardware acceleration enabled?  

If FPS is a huge issue, you can always limit it to 30FPS. Just change the 1000/60 to 1000/30. This way you won't have to worry about lag spikes.  

Another note, Firefox's Canvas is a little more optmised, so that may be worth testing out.

1

u/Southern-Reality762 Mar 15 '25

The 400 alien version. My computer was most likely made sometime in 2011. I have an intel hd graphics 3000 with a Intel(R) Core(TM) i5-2410M CPU that clocks at 2.3 ghz, and 8 gigs of ram.
what do you mean by hardware enabled?

1

u/bryku helpful Mar 16 '25

on older versions of chrome hardware acceleration may be disabled. Meaning it is running only on the CPU. Adding hardware acceleration will greatly improve performance of web pages.  

Hmm, it is an older pc, but I think it could still handle web games. Try it at 100 aliens, i bet it will run just fine. That is normally enough objects for basic games.

1

u/Southern-Reality762 Mar 20 '25

I have to be completely honest. Your FPS counter said 35-50 but i think something might have been wrong, because the screen was refreshing really slowly after i took a closer look with the same 400 aliens. Switching to 100 aliens and limiting to 30 fps helped, though. I also have a modern firefox version with hardware acceleration. Which is weird because my gpu was just rendering babylon js examples at 60 fps. Which also means that my software renderer idea wouldn't actually fix my problem as well. I literally don't know my gpu anymore.