Skip to content

BMaxV/pygame-web.github.io

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

pygame-web.github.io

CDN root used by pygbag

Github repo, and older runtimes

This software does not track usage at all, not even for statistics purpose so if you like it :

please do not forget to ⭐⭐ Star ⭐⭐ it !

Pygbag WIKI

Do NOT forget to read the coding section for WASM. You WILL have to change a few lines to classic python/pygame code.

IMPORTANT ALL: add --template noctx.tmpl to pygbag command line when using 3D/WebGL

IMPORTANT WIN32 users :

  • do not use python installed from windows store, use an official python.org build you can check version installed with py --list command. If python/pygbag is not installed in your PATH env, use the command py -m pygbag

  • do not use "\" a path separator, pygbag is POSIX and use "/" instead eg open("img/my_image.png","rb) the change should not interfere and still work on recent Win32.

IMPORTANT MAC users : if you get SSL error, use the file "Install Certificates.command" in Applications/Python 3.XX

IMPORTANT Linux users: when using webusb ftdi serial emulation use sudo rmmod ftdi_sio after plugging devices.

IMPORTANT ALL: when importing complex wheels that depend on each other, always put them in order (but numpy first) in main.py

IMPORTANT ALL: Please do not use wav/mp3 audio formats when packaging, pygbag would not work.

Before packaging, adapt your code this way if you still want wav format on desktop :

if sys.platform == "emscripten":
    snd = pygame.mixer.Sound("sound.ogg")
else:
    snd = pygame.mixer.Sound("sound.wav") # or .WAV,.mp3,.MP3

also avoid raw format like BMP for your assets they are too big for web use. prefer PNG or JPG


template project

There is none actually, because pygbag is not a framework it is just a friendly web version of official CPython (nothing has been changed, just some facilities added). Most desktop code will run (and will continue to run) with only a few lines changes. This is actually true for games but for applications it can be very difficult to port, even sometimes impossible.

Try to avoid relying on CPython stdlib for web operations, GUI (like tk) or I/O as it is very synchronous, platform specific and will probably stay that way.

Note about GUI: pygame-ce provides pygame_gui, Panda3D provides directgui and Harfang3D imgui => and they are all cross platform.

As alternative using pygame or pygbag supported game engines will ensure you platform independence including access to mobile ones.

basic structure of a game should be like :

test
├── img
│   ├── pygc.bmp
│   ├── pygc.png
│   └── tiger.svg
├── main.py
└── sfx
    └── beep.ogg

then run pygbag test/main.py against it, and first goes to http://localhost:8000?-i (with terminal and debugging info, for older pygbag version use http://localhost:8000#debug instead) or http://localhost:8000 (fullscreen windowed when it is running ok)

usefull additions to your .gitignore

*.wav
*.mp3
*.pyc
*.egg-info
*-pygbag.???
/build
/dist

[Coding]

mandatory when importing packages : put the "import " at top of main.py ( eg import numpy, matplotlib )

if using pygame-zero : put #!pgzrun near the top of main ( 2nd line is perfect if file already has a shebang ) Note: pgzero is mostly untested

[Debugging / Desktop Simulator]

  • enter debug mode
  • while working you can access simulator of web loop by replacing import asyncio by import pygbag.aio as asyncio at top of main.py and run program directly from main.py folder
  • TODO: android remote debugging via chromium browsers series
  • TODO: universal remote debugging via irc client or websocket using pygbag.net

[Running]

[packaging]

how to package a game

[Publishing]


Demos on github pages :

(for testing, may not always work since they use daily/weekly devel version)

heavy cpu load not for low-end devices:

Perfect Rain

Alien Dimension

Light cpu load :

Breakout

PyChess

Penguins Can't Fly !

John's Adventure

3D Tic-Tac-Toe

Arachnoids

Sudoku Solver

view code from above games and others on github

[view the code]

Please ! use the tag pygame-wasm for your projects hosted on Github and also add a favicon.png icon 32x32 next to your game main.py, so it is picked up by default.

Demos on itch.io:

( expected to be stable )

games on itch.io

Script demos

nb : code is read-only, prefer right-click then open in new window.

i18n bidi,complex scripts

camera

Panda3D

Audio Record/Play

Html output


Technology:

devlog

Python Wasm explained by core dev Christian Heimes (youtube video)

Early demos from above talk, may not fully work as intended :)

pygame tech demo PyCon DE & PyData Berlin 2022

Galaxy Attack

French : Python WebAssembly at PyCon FR 2023 Pour quoi, pour qui et comment

current status

explore current issues

package porting

PyPI stats

pyodide/pyscript

Thanks for supporting pygame-ce and pygbag. Without support now, there would not be pygame-ce + pygbag later.

Hello from the pygame-ce community.

Connect with Discord

Pygame community

WebAssembly/Python

Work in Progress, PR welcomed, propose links to games or tutorials, please contribute !!!

edit this page

About

Run python and pygame code in your html

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published