Description
Feature requested
Support to distribute and play arcade based games within the browser.
Why?
Packaging Python does get easier and with utilisation of free GitHub Actions like New Arcade Game Template it is possible to automatically package Arcade based games as shippable artefacts for Win, MacOS and Linux.
These artefacts still have a huge drawback. They are reported as dangerous by the different OS, which can only be solved by paying a lot of money to sign the created artefacts and make them "trusted". Users have to actively ignore or disable security measures to play those games.
This is the reason why multiple GameJams already restrict submissions to browser supported artefacts.
In game development this is not a huge limitation, because other projects already support this (Unity, Godot).
In addition PyGame already have their foot in the door of browser support.
- https://pygame-web.github.io/
- which lead to over 50 PyGame based games available on itch.io
Why does it matter?
For me as Arcade Dev, I have a high interest, that my efforts I spend on Arcade, bring value to other game developer or people who learn Python. Projects like PyScript are IMHO the next big step to push Python to become the most used language. Supporting game development on a PyScript base would give us a push in attention and new users. It also would make it really simple to get started.
My current state of knowledge so far
- There is already a old issue on Pyglet, to support browser: Run pyglet in a web browser pyglet/pyglet#949
- pmp-p already had a working example of Pyglet using WebGL based on
headless
-mode and EGL rendering. - The PoC already covered changes to run the pyglet event loop async
- The main difference between the PoC and a PyScript based setup is the runtime uses Python-WASM which provides an
embed
helper module, which should be easy to replace because it just provides the EGL context - Still pmp-p mentioned in a discord chat at PyScript
most of the work in pyglet is freetype, input ( all of them ! ) and audio
if i was about to make it real , i would use arcade -> pysdl2 + zengl , that way long term it would also work with micropython - Micropython support would be cool, because it has a smaller footprint, but libraries like pillow are already usable via pyodide, not sure if we would be able to find a way around that
- pmp-p already had a working example of Pyglet using WebGL based on
- @pushfoo already summarised some discussions on this topic in an old issue of arcade Enhancement request - Python Arcade for browser games #1215
- Examples exist how to access WebGL 2 context of a html canvas: Using WebGL2 fails within pyodide (SDL_GL_CreateContext => EGL_BAD_CONFIG) emscripten-core/emscripten#21849
- Pyglet devs already signalised, that they are open to support the work on browser support, but it is not their highest priority right now.
To compile all of these
- Rendering should be possible and we have PoC that show that.
- Things which are not covered
- Inputs
- Controller
- Fonts
- Audio
How I test:
Getting started with pyglet in the browser is pretty easy, it just not works :D
Store this as index.html
and use python -m -m http.server -d ./ -b 127.0.0.1
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="stylesheet" href="https://pyscript.net/releases/2025.2.2/core.css">
<script type="module" src="https://pyscript.net/releases/2025.2.2/core.js"></script>
</head>
<body>
<canvas id="canvas"></canvas>
<script type="py" config='{"packages":["pyglet"]}'>
import pyglet
print(pyglet.version)
window = pyglet.window.Window()
image = pyglet.resource.image("kitten.jpg")
@window.event
def on_draw():
window.clear()
image.blit(0, 0)
pyglet.app.run()
</script>
</body>
</html>
I set up a repo to test it myself and use the fork of pmp-p: https://github.com/eruvanos/arcade-web-support/blob/pygbag/README-WEB.md
Activity