|
| 1 | +# PyGame Support |
| 2 | + |
| 3 | +!!! Danger |
| 4 | + |
| 5 | + **Support for PyGame-CE is experimental** and its behaviour is likely to |
| 6 | + change as we get feedback and bug reports from the community. |
| 7 | + |
| 8 | + Please bear this in mind as you try PyGame-CE with PyScript, and all |
| 9 | + feedback, bug reports and constructive critique is welcome via discord |
| 10 | + or GitHub. |
| 11 | + |
| 12 | + |
| 13 | +[PyGameCE](https://pyga.me/) is a Python library for building powerful games |
| 14 | +(so says their website). They also say, to get started you just need to |
| 15 | +`pip install pygame-ce`. |
| 16 | + |
| 17 | +Thanks to work in the upstream [Pyodide project](https://pyodide.org/) |
| 18 | +PyGame-CE is available in PyScript and to get started all you need to do is: |
| 19 | +`<script type="py-game" src="my_game.py"></script>` Now you don't even need to |
| 20 | +`pip install` the library! It comes with PyScript by default, and you can share |
| 21 | +your games via a URL! |
| 22 | + |
| 23 | +!!! Info |
| 24 | + |
| 25 | + Please refer to |
| 26 | + [PyGame-CE's extensive documentation](https://pyga.me/docs/) for how to |
| 27 | + create a game. Some things may not work because we're running in a |
| 28 | + browser context, but play around and let us know how you get on. |
| 29 | + |
| 30 | +## How it works |
| 31 | + |
| 32 | +When a `<script type="py-game"></script>` element is found on the page a |
| 33 | +Pyodide instance is bootstrapped with the `pygame-ce` package already included. |
| 34 | +Differently from other scripts, `py-game` cannot currently work through a |
| 35 | +worker and it uses an optional target attribute to define the `<canvas>` |
| 36 | +element id that will be used to render the game. If no target attribute is |
| 37 | +defined, the script assumes there is a `<canvas id="canvas">` element already |
| 38 | +on the page. |
| 39 | + |
| 40 | +A config attribute can be specified to add extra packages but right now that's |
| 41 | +all it can do. |
| 42 | + |
| 43 | +This is an experiment, but: |
| 44 | + |
| 45 | +* It is possible to use regular PyScript to load the pygame-ce package and use |
| 46 | + all the other features. But there be dragons! This helper simply allows |
| 47 | + multiple games on a page and forces game logic to run on the main thread to |
| 48 | + reduce confusion around attributes and features when the `pygame-ce` package |
| 49 | + is meant to be used. Put simply, we make it relatively safe and easy to use. |
| 50 | +* The fact `pygame-ce` is the default "game engine" does not mean in the future |
| 51 | + PyScript won't have other engines also available. |
| 52 | +* Once again, as this is an experiment, we welcome any kind of feedback, |
| 53 | + suggestions, hints on how to improve or reports of what's missing. |
| 54 | + |
| 55 | +Other than that, please go make and share wonderful games. We can't wait to see |
| 56 | +what you come up with. |
0 commit comments