English | 简体中文
This module provides most of the functions of pygame-zero for skulpt, and can use pygame-zero to write some simple 2d games in the web environment and run based on PIXI.js
Use npm:
npm install skulpt-pygame-zero
Use cdn:
https://cdn.jsdelivr.net/npm/skulpt-pygame-zero/dist/main.js
-
Import module
// webpack import 'skulpt-pygame-zero' // cdn <script src="https://cdn.jsdelivr.net/npm/skulpt-pygame-zero/dist/main.js"></script>
-
Use
PyGameZero.usePyGameZero
to wrapread
functionSk.configure({ .... other settings // before read: builtinRead, // after read: PyGameZero.usePyGameZero(builtinRead), __future__: Sk.python3, });
-
Designated container
html
<div id="stage"></div>
javascript
PyGameZero.setContainer(document.getElementById('stage'))
-
It is best to execute a reset method before running
// insert before running PyGameZero.reset(); // running skulpt Sk.misceval.asyncToPromise(function() { return Sk.importMainWithBody("<stdin>", false, pythonCode, true); });
Copy the code of test/simple.py for testing
-
Image resources can only be loaded via links
Actor('https://static.lipten.link/blogs/pig1.png')
-
You can also pass in multiple pictures
pig = Actor(('https://static.lipten.link/blogs/pig1.png','https://static.lipten.link/blogs/pig2.png')) # then ute frame=2 to switch the second photo pig.frame = 2
- images
- music.fadeout
- music.queue
- Actor keyword argument: pos, topleft, topright, bottomleft, bottomright, midtop, midleft, midright, midbottom or center
- Anchor point
- Tone Generator
git clone git@github.com:lipten/skulpt-pygame-zero.git
- Install the required
parcel
usingnpm i -g parcel-bundler
- Execute the following commands in the project directory:
npm run build