Skip to content

Commit 0e054c5

Browse files
authored
keep some linear critical infos on landing page
1 parent e200044 commit 0e054c5

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

README.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,125 @@ This is the CDN root used by [Pygbag](https://pypi.org/project/pygbag/) ([Source
44

55
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!
66

7+
## Important points
8+
9+
**<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>**
10+
11+
### All operating systems
12+
13+
- Name your main game script `main.py` and put it in the root folder of your game.
14+
- Make your main loop async-aware and use `asyncio.sleep(0)` every iteration to give control back to the main thread.
15+
- Add `--template noctx.tmpl` to pygbag command line if using 3D/WebGL.
16+
- Put the import statements of complex packages in order (but numpy first) at the top of `main.py`.
17+
- 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.
18+
- 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.
19+
- Make sure all audio files are in OGG format, and all files are compressed. (that is, not in WAV/AIFF)
20+
- Avoid raw formats like BMP for your image assets, they are too big for web use; use PNG/WEBP or JPG instead.
21+
22+
- Do not use filenames like `*-pygbag.*` that pattern is reserved for pygbag internal use (optimizing pass).
23+
24+
Before packaging, adapt your code this way if you still want WAV/MP3 format on desktop:
25+
```py
26+
if sys.platform == "emscripten":
27+
snd = pygame.mixer.Sound("sound.ogg")
28+
else:
29+
snd = pygame.mixer.Sound("sound.wav") # or .WAV, .mp3, .MP3, etc.
30+
```
31+
32+
if you have heightmaps in your assets use `--no_opt` to prevent png recompression.
33+
34+
if you want to keep pixelated look whatever the device screen size is use:
35+
```py
36+
import sys, platform
37+
if sys.platform == "emscripten":
38+
platform.window.canvas.style.imageRendering = "pixelated"
39+
```
40+
41+
### Windows
42+
43+
- Use Python that was downloaded from python.org rather than the Windows Store. You can check installed version(s) with the `py --list` command.
44+
- 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.
45+
46+
### MacOS
47+
48+
- If you get a SSL error, use the file `Install Certificates.command` in `Applications/Python 3.XX`.
49+
50+
### Linux
51+
52+
- When using webusb ftdi serial emulation, use `sudo rmmod ftdi_sio` after plugging devices.
53+
54+
55+
## Template
56+
57+
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.
58+
59+
Basic structure of a game (available [here](https://github.com/pygame-web/pygbag/tree/main/test)):
60+
```
61+
test
62+
├── img
63+
│   ├── pygc.bmp
64+
│   ├── pygc.png
65+
│   └── tiger.svg
66+
├── main.py
67+
└── sfx
68+
└── beep.ogg
69+
```
70+
71+
Useful .gitignore additions:
72+
```
73+
*.wav
74+
*.mp3
75+
*.pyc
76+
*.egg-info
77+
*-pygbag.???
78+
/build
79+
/dist
80+
```
81+
82+
83+
## Coding
84+
85+
- [General Python-WASM](/wiki/python-wasm/)
86+
- [With Pygbag specifically](/wiki/pygbag-code/)
87+
- [Pygbag code examples](/wiki/pygbag-code/#pygbag-code-specificssamples)
88+
89+
## Adding modules
90+
91+
- [List of available wheels](/wiki/pkg/)
92+
- [requesting modules](https://github.com/pygame-web/pkg-porting-wasm/issues)
93+
94+
When importing non-stdlib 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:
95+
```
96+
# /// script
97+
# dependencies = [
98+
# "six",
99+
# "bs4",
100+
# "markdown-it-py",
101+
# "pygments",
102+
# "rich",
103+
# "mdurl",
104+
# "textual",
105+
# ]
106+
# ///
107+
```
108+
109+
110+
## Debugging / Desktop Simulator
111+
- The REPL shortcut http://localhost:8000?-i, REPL will (should) run concurrently as main.py.
112+
- [How to enter debug mode](/wiki/pygbag-debug/)
113+
- 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.
114+
- TODO: Android remote debugging via [chromium browsers series](https://developer.chrome.com/docs/devtools/remote-debugging/).
115+
- TODO: Universal remote debugging via IRC Client or websocket using pygbag.net.
116+
117+
118+
119+
There's number of command line options : read Pygbag's [project description](https://pypi.org/project/pygbag/) for a more detailed overview.
120+
121+
7122
Visit the [wiki](/wiki/) to get started!
8123

124+
125+
9126
**Work in progress, pull requests welcomed. Feel free to propose links to games or tutorials. Please contribute!!!**
10127

11128
[Edit this page](https://github.com/pygame-web/pygame-web.github.io/edit/main/README.md)

0 commit comments

Comments
 (0)