Building Python/PyGame games for browser

It's 2023. Your car can send you emails, your refrigerator can get malware --- and you can run Python in a web browser!

web_sc.png

PygBag is an open-source web packager for Python/PyGame. It turns your PyGame application into an Itch.io-ready HTML5 build with very little effort (under the hood, it's running a Python interpreter in web assembly).

Play and rate is already halfway over, but I decided to add a web build to learn about the tools and hopefully make it easier to play my game on other platforms. Here's what I learned making an HTML5 build for Holding Out with PygBag: - Performance matters. A lot. My desktop build could easily run at 100 FPS on my laptop, but I had to make a lot of performance optimizations to make a viable web build. Graphics operations are particularly expensive; I ended up removing the "vignette" effect on my game for the web build to improve frame rate. - Audio is finnicky. The web build is prone to audio stuttering and delays, especially if performance is poor. I suspect there's an audio buffer that the browser can't update during synchronous operations, so you either need to make sure your game loop is very fast or add in additional asynchronous "sleep" statements in the middle of your update/render code. - It's not that hard. Aside from the performance improvements, there are actually very few code changes required to get this working.

gary.gif

I'll stop short of offering a tutorial, because this YouTube video covers it better than I could hope to in a blog post:

https://www.youtube.com/watch?v=6PhDmpBcezQ

Good luck everyone for the rest of play and rate!