是否可以使用Pyscript在浏览器上使用PyGame进行游戏?
我已经使用Pygame制作了一个小型太空入侵游戏,我想知道是否可以使用Pyscript在浏览器上玩它。这甚至可能吗?我必须重写所有内容吗?
I have made a small space invader game using pygame and I was wondering if I could play it on the browser using pyscript. Is this even possible ? Do I have to rewrite everything ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不,目前在Pyscript中不支持Pygame。我不确定哪些最好的方法是找出哪些包装 支持,但是我设法将以下内容拼凑在一起:
pygame尚未得到pyodide的支持。编辑: pygame被合并于毕林德,将在以后的发行版中。
您可以使用以下测试脚本来查看是否支持软件包:
这基本上只是一个“尝试并查看发生的事情”脚本,如果不支持软件包,它将在控制台中丢弃错误。您会看到的错误将是
No, Pygame is not supported in PyScript at this time. I'm not sure what is the best way to find out what packages are supported, but I have managed to piece together the following:
Pygame is not yet supported by Pyodide.Edit: Pygame has been merged in Pyodide and will be available in a future release.
You can use the following test script to see if a package is supported:
This is basically just a "try it and see what happens" script that will throw an error in the console if a package is not supported. The error you'll see will be
是的,这是可能的,但尚未获得,因为:
Pyscript使用陀螺赛,倍陀在游戏中不是优化的,而是用于科学堆栈和笔记本电脑的演示文稿。
今天,我建议使用pygbag https://pypi.org/project/project/pygbag/ 来自 https://pygame-web.github.io 。它使用适用于来自PANDA3D WebGL端口的Pygame的相同原理,使用用于现代浏览器的Web组件。
(而且,如果您真的想支持Pyscript标签,则可能会找到一种方法)。
Yes it's possible but has not been made available because :
pyscript uses pyodide, pyodide is NOT optimized for games but for scientific stack instead and notebooks presentations.
Today, i'd recommand using pygbag https://pypi.org/project/pygbag/ from https://pygame-web.github.io. It uses the same principles applied to pygame coming from Panda3D webgl port using Web Assembly for modern browsers.
( and if you really want to support pyscript tags you could probably find a way ).
您可以使用pygbag做到这一点。
这是pygbag的链接: pygbag
在这里链接到一篇文章:浏览器中的pygame
You can use PygBag do do so.
Here is the link to PygBag : PygBag
And here a link to an article: Pygame in a Browser
无论如何,您都不能使用大多数Pygame,因为Pyscript只会渲染Python一次,因此您不能做诸如Pygame进行更改帧之类的事情所需的循环之类的事情。
You can't use most of pygame anyway because pyscript will only render python once, so you can't do stuff like loops which are necessary for pygame to do stuff like change frames.