|
1 | 1 | # pygame-web.github.io
|
2 | 2 |
|
3 |
| -This is the CDN root used by [Pygbag](https://pypi.org/project/pygbag/) ([Source code](https://github.com/pygame-web/pygbag)/[Old runtimes](https://github.com/pygame-web/archives)) and the site of its [wiki](https://pygame-web.github.io/wiki/pygbag). |
| 3 | +This is the CDN root used by [Pygbag](https://pypi.org/project/pygbag/) ([Source code](https://github.com/pygame-web/pygbag)/[Old runtimes](https://github.com/pygame-web/archives)) and the site of its [wiki](/wiki/). |
4 | 4 |
|
5 | 5 | Pygbag does not track usage at all, not even for statistical purposes. If you like it, please [star](https://github.com/pygame-web/pygbag/stargazers) the repository!
|
6 | 6 |
|
7 |
| -Check out some [demos](#demos-on-itchio) before you start! |
8 |
| - |
9 |
| -## Important points |
10 |
| - |
11 |
| -Read Pygbag's [project description](https://pypi.org/project/pygbag/) for a more detailed overview. A full packaging guide can be found [here](https://pygame-web.github.io/wiki/pygbag/). |
12 |
| - |
13 |
| -**<ins>Also, read the page on [making your code compatible with browser game loop](https://pygame-web.github.io/wiki/python-wasm). You will probably have to change some of your code.</ins>** |
14 |
| - |
15 |
| -### All operating systems |
16 |
| - |
17 |
| -- Name your main game script `main.py` and put it in the root folder of your game. |
18 |
| -- Make your main loop async-aware and use `asyncio.sleep(0)` every iteration to give control back to the main thread. |
19 |
| -- Add `--template noctx.tmpl` to pygbag command line if using 3D/WebGL. |
20 |
| -- Put the import statements of complex packages in order (but numpy first) at the top of `main.py`. |
21 |
| -- Avoid using CPython's standard library for web operations, GUI (like tkinter), or I/O as it is very synchronous/platform-specific and will probably stay that way. In terms of GUI alternatives, [pygame_gui](https://pypi.org/project/pygame_gui) works on top of [pygame-ce](https://pyga.me), [Panda3D](https://www.panda3d.org/) provides [directgui](https://docs.panda3d.org/1.10/python/programming/gui/directgui/index) and Harfang3D provides imgui. They are all cross-platform. |
22 |
| -- You can add a square image file named `favicon.png` in your game's root folder to make Pygbag use it as the web package's favicon. |
23 |
| -- Make sure all audio files are in OGG format, and all files are compressed. (that is, not in WAV/AIFF) |
24 |
| -- Avoid raw formats like BMP for your image assets, they are too big for web use; use PNG/WEBP or JPG instead. |
25 |
| - |
26 |
| -- Do not use filenames like `*-pygbag.*` that pattern is reserved for pygbag internal use (optimizing pass). |
27 |
| - |
28 |
| -Before packaging, adapt your code this way if you still want WAV/MP3 format on desktop: |
29 |
| -```py |
30 |
| -if sys.platform == "emscripten": |
31 |
| - snd = pygame.mixer.Sound("sound.ogg") |
32 |
| -else: |
33 |
| - snd = pygame.mixer.Sound("sound.wav") # or .WAV, .mp3, .MP3, etc. |
34 |
| -``` |
35 |
| - |
36 |
| -if you have heightmaps in your assets use `--no_opt` to prevent png recompression. |
37 |
| - |
38 |
| -if you want to keep pixelated look whatever the device screen size is use: |
39 |
| -```py |
40 |
| -import sys, platform |
41 |
| -if sys.platform == "emscripten": |
42 |
| - platform.window.canvas.style.imageRendering = "pixelated" |
43 |
| -``` |
44 |
| - |
45 |
| -### Windows |
46 |
| - |
47 |
| -- Use Python that was downloaded from python.org rather than the Windows Store. You can check installed version(s) with the `py --list` command. |
48 |
| -- Use `/` instead of `\` as a path separator (e.g. `img/my_image.png` instead of `img\my_image.png`). The path should still be valid on newer Windows versions. |
49 |
| - |
50 |
| -### MacOS |
51 |
| - |
52 |
| -- If you get a SSL error, use the file `Install Certificates.command` in `Applications/Python 3.XX`. |
53 |
| - |
54 |
| -### Linux |
55 |
| - |
56 |
| -- When using webusb ftdi serial emulation, use `sudo rmmod ftdi_sio` after plugging devices. |
57 |
| - |
58 |
| -## Template |
59 |
| - |
60 |
| -There is actually none, because Python-WASM is just a web-friendly version of CPython REPL with [some added facilities](https://discuss.python.org/t/status-of-wasm-in-cpythons-main-branch/15542/12?u=pmp-p). Most desktop code will run (and continue to run) with only a few changes. |
61 |
| - |
62 |
| -Basic structure of a game (available [here](https://github.com/pygame-web/pygbag/tree/main/test)): |
63 |
| -``` |
64 |
| -test |
65 |
| -├── img |
66 |
| -│ ├── pygc.bmp |
67 |
| -│ ├── pygc.png |
68 |
| -│ └── tiger.svg |
69 |
| -├── main.py |
70 |
| -└── sfx |
71 |
| - └── beep.ogg |
72 |
| -``` |
73 |
| - |
74 |
| -Useful .gitignore additions: |
75 |
| -``` |
76 |
| -*.wav |
77 |
| -*.mp3 |
78 |
| -*.pyc |
79 |
| -*.egg-info |
80 |
| -*-pygbag.??? |
81 |
| -/build |
82 |
| -/dist |
83 |
| -``` |
84 |
| - |
85 |
| -## Coding |
86 |
| - |
87 |
| -- [General Python-WASM](https://pygame-web.github.io/wiki/python-wasm/) |
88 |
| -- [With Pygbag specifically](https://pygame-web.github.io/wiki/pygbag-code/) |
89 |
| -- [Pygbag code examples](https://pygame-web.github.io/wiki/pygbag-code/#pygbag-code-specifics-samples-) |
90 |
| - |
91 |
| -## Adding modules |
92 |
| - |
93 |
| -- [List of available wheels](https://pygame-web.github.io/wiki/pkg/) |
94 |
| -- [requesting modules](https://github.com/pygame-web/pkg-porting-wasm/issues) |
95 |
| - |
96 |
| -When importing complex packages (for example, numpy or matplotlib), you must put their import statements at top of `main.py`. You should also add a metadata header as specified by [PEP 723](https://peps.python.org/pep-0723/), for example: |
97 |
| -``` |
98 |
| -# /// script |
99 |
| -# dependencies = [ |
100 |
| -# "six", |
101 |
| -# "bs4", |
102 |
| -# "markdown-it-py", |
103 |
| -# "pygments", |
104 |
| -# "rich", |
105 |
| -# "mdurl", |
106 |
| -# "textual", |
107 |
| -# ] |
108 |
| -# /// |
109 |
| -``` |
110 |
| - |
111 |
| -If using pygame-zero (mostly untested), put `#!pgzrun` near the top of main.py. (2nd line is perfect if the file already has a shebang) |
112 |
| - |
113 |
| -## Debugging / Desktop Simulator |
114 |
| - |
115 |
| -- [How to enter debug mode](https://pygame-web.github.io/wiki/pygbag-debug/) |
116 |
| -- While working, you can access the simulator of the web loop by replacing `import asyncio` by `import pygbag.aio as asyncio` at top of main.py and run the program from the folder containing it. |
117 |
| -- TODO: Android remote debugging via [chromium browsers series](https://developer.chrome.com/docs/devtools/remote-debugging/). |
118 |
| -- TODO: Universal remote debugging via IRC Client or websocket using pygbag.net. |
119 |
| - |
120 |
| -## Running |
121 |
| - |
122 |
| -- [Pygbag-script](https://pygame-web.github.io/wiki/pygame-script/) (WIP) |
123 |
| -- [REPL](https://pygame-web.github.io/showroom/python.html?-i-&-X-dev#https://gist.githubusercontent.com/pmp-p/cfd398c75608504293d21f2642e87968/raw/773022eef4a2cc676ab0475890577a2b5e79e429/hello.py) |
124 |
| -- [CPython test suite](https://pygame-web.github.io/showroom/pythondev.html?-d#src/testsuite.py%20all) (WIP) |
125 |
| - |
126 |
| -## Publishing |
127 |
| - |
128 |
| -- [Github Pages](https://pygame-web.github.io/wiki/pygbag/github.io/) |
129 |
| -- [Itch.io](https://pygame-web.github.io/wiki/pygbag/itch.io/) |
130 |
| - |
131 |
| -## Demos |
132 |
| - |
133 |
| -### Demos on itch.io |
134 |
| - |
135 |
| -- [Games using Python-WASM](https://itch.io/c/2563651/pygame-wasm) (Expected to be stable) |
136 |
| -- [Panda3D demos](https://itch.io/c/3724091/panda3d-wasm) (Experimental) |
137 |
| - |
138 |
| -### Demos on Github Pages |
139 |
| - |
140 |
| -These are provided for testing purposes only, and might not always work since they use development versions of Pygbag. |
141 |
| - |
142 |
| -#### Heavy CPU load, not for low-end devices |
143 |
| - |
144 |
| -- [Perfect Rain](https://pmp-p.github.io/pygame-perfect-rain-wasm/) |
145 |
| -- [Alien Dimension](https://pmp-p.github.io/pygame-alien-dimension-wasm/) |
146 |
| - |
147 |
| -#### Light CPU load |
148 |
| - |
149 |
| -- [Breakout](https://pmp-p.github.io/pygame-breakout-wasm/index.html) |
150 |
| -- [PyChess](https://pmp-p.github.io/pygame-pychess-wasm/index.html) |
151 |
| -- [Penguins Can't Fly!](https://pmp-p.github.io/pygame-PenguinsCantFly-wasm/) |
152 |
| -- [John's Adventure](https://pmp-p.github.io/pygame-JohnsAdventure-wasm/) |
153 |
| -- [3D Tic-Tac-Toe](https://pmp-p.github.io/pygame-ttt-3d-wasm/) |
154 |
| -- [Arachnoids](https://pmp-p.github.io/pygame-arachnoids-wasm/) |
155 |
| -- [Sudoku Solver](https://www.pete-j-matthews.com/Sudoku-Solver/) |
156 |
| - |
157 |
| -Source code for these games can be found [here](https://github.com/pmp-p?tab=repositories&q=pygame-.-wasm&sort=name). You can tag your Github repositories with [[pygame-wasm]](https://github.com/topics/pygame-wasm). |
158 |
| - |
159 |
| -### Script demos |
160 |
| - |
161 |
| -The code is read-only, so you should right-click then open in a new window. |
162 |
| - |
163 |
| -- [i18n bidi, complex scripts](/showroom/pypad_git.html?-i#src/test_hb.py) |
164 |
| -- [Camera](/showroom/pypad_git.html?-i#src/test_vidcap.py) |
165 |
| -- [Panda3D](/showroom/pypad_dev.html?-i#src/test_panda3d_cube.py) |
166 |
| -- [Audio Record/Play](/showroom/pypad_dev.html?-i#src/test_audio.py) |
167 |
| -- [HTML output](/showroom/pypad_dev.html?-i#src/test_html.py) |
168 |
| - |
169 |
| -## Technology |
170 |
| - |
171 |
| -- [Initial discussion](https://github.com/pygame/pygame/issues/718) |
172 |
| -- [Discussion at pygame-ce repo](https://github.com/pygame-community/pygame-ce/issues/540) |
173 |
| -- [Python-WASM explained by core dev Christian Heimes (video)](https://www.youtube.com/watch?v=oa2LllRZUlU) |
174 |
| - |
175 |
| -### Early demos from above talk, may not work as intended :) |
176 |
| - |
177 |
| -- [Pygame tech demo PyCon DE & PyData Berlin 2022](https://pmp-p.github.io/pygame-wasm/) |
178 |
| -- [Galaxy Attack](https://pmp-p.github.io/pygame-galaxy-attack-wasm/) |
179 |
| - |
180 |
| -Python WebAssembly at PyCon FR 2023 (in French): |
181 |
| -[Pour quoi, pour qui et comment](https://harfang3d.github.io/pyconfr2023/#1) |
182 |
| - |
183 |
| -## Status |
184 |
| - |
185 |
| -- [Current issues](https://github.com/pygame-web/pygbag/issues) |
186 |
| -- [Package porting](https://github.com/pygame-web/pkg-porting-wasm/issues) |
187 |
| -- [PyPI stats](https://pepy.tech/project/pygbag) |
188 |
| - |
189 |
| -## Other Pythons in browser |
190 |
| - |
191 |
| -- [Pyodide/Pyscript](https://github.com/pyodide/pyodide) ( py3.12+ not suitable for heavy games, music or 3D ) |
192 |
| -- [Micropython/Pyscript](https://www.npmjs.com/package/@micropython/micropython-webassembly-pyscript) ( py3.4, no pygame, but pysdl2/javascript libraries possible ) |
193 |
| -- PocketPy, not any Python spec compliant but sometimes close. Can make Terminal/raylib based games. |
194 |
| - |
195 |
| -## Support |
196 |
| - |
197 |
| -- [Pygame Community](https://pyga.me/) |
198 |
| - |
199 |
| -## Connect |
200 |
| - |
201 |
| -- [Pygame Community Discord Server](https://discord.gg/p7RjnVNTcM) |
202 |
| -- [WebAssembly/Python Discord Server](https://discord.gg/MCTM4xFDMK) |
203 |
| - |
204 |
| -Thanks for reading and supporting pygame-ce and pygbag. These tools could not have existed without your support. |
| 7 | +Visit the [wiki](/wiki/) to get started! |
205 | 8 |
|
206 | 9 | **Work in progress, pull requests welcomed. Feel free to propose links to games or tutorials. Please contribute!!!**
|
207 | 10 |
|
|
0 commit comments