27

I have 3 game libraries installed on my PC: pyglet, pygame and Panda3D.

I would like to create a 2D game and make it a web browser game so i can put it on facebook.

I know that Panda3D has a web-browser-plugin. Panda3D is for 3D games mainly.

Therefore, I'm asking, is it possible to play a pyglet or pygame game in a browser? If not, what Python library do you recommend?

Brigand
  • 84,529
  • 20
  • 165
  • 173
Lynob
  • 5,059
  • 15
  • 64
  • 114
  • Not sure about pyglet or pygame. Probably not. But you might want to check out (http://pyjs.org/) – c0m4 Dec 12 '11 at 18:52
  • 1
    e.g.: [replit.com](https://replit.com/@Rabbid76/PyGame-RotateAroundPivot#main.py) – Rabbid76 May 11 '21 at 19:13
  • both pygame and Panda3D can now run in the browser for pygame see https://github.com/pygame-web ( demo pmp-p.github.io/pygame-wasm/ ) and for panda3d see https://rdb.name/panda3d-webgl.md.html ( demo https://rdb.name/panda3d-webgl/editor.html ) – Pmp P. Jun 06 '22 at 13:39

5 Answers5

12

Neither pyglet nor pygame will run in a browser. I wouldn't really recommend using Python at all if you target is a web browser. JavaScript (with HTML5 Canvas), Flash, or Java applets are is better suited for that environment.

If you're dedicated to the idea of using Python, there are a number of projects that can compile Python into JavaScript. There are some mentioned on the Python wiki. Here are a few:

You'll need to write your own graphics and audio systems, though, since none of those projects can convert the native code needed by pyglet and pygame into JavaScript.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Snowball
  • 11,102
  • 3
  • 34
  • 51
  • 3
    Ah, you might be interested in Jython, then. I didn't think about it yesterday. A search for "jython applets" will lead you to some information on the subject. – Snowball Dec 27 '11 at 08:37
4

It requires a bit of reprogramming, but i made a pygame library "port" to the browser/nodewebkit using Brython and GameJS. You can program using a version of pygame and python 3 in the browser. You can check it out at https://github.com/asherwunk/pygjs

4

Today, i'd recommand using pygbag https://pypi.org/project/pygbag/ from https://pygame-web.github.io. It uses the same principles from Panda3D webgl port ( not the old plugin) using Web Assembly for modern browsers.

Pmp P.
  • 407
  • 3
  • 9
3

An option is to use repl.it. It allows creating Python/PyGame scripts and multiplayer coding. When creating a new repl, select the Pygame template:


Example: repl.it/@Rabbid76/PyGame-TransparentShapes

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
0

I just found this website https://trinket.io/features/pygame that allows you to run pygame from this website! But it's extremely slow. It should work from your browser but it'll take forever to run it.

AzlanCoding
  • 209
  • 2
  • 11