Python 游戏库 Pygame 和 Pyglet 之间的区别?

发布于 2024-07-09 16:17:43 字数 1723 浏览 8 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

叹倦 2024-07-16 16:17:43

我正在考虑使用 Pygame 和 Pyglet 来开发一个小型 2D 射击游戏,在查看了源代码和一些教程后,我选择了 Pyglet。 我对结果非常满意。

Pyglet 立即工作并且使用起来很愉快,并且概念上非常干净。 对我来说,它确实有一种Pythonic的感觉:你可以很快地得到一个简单易读的例子,并且它使用装饰器来处理事件,效果很好。 它也没有强制特定的程序结构,这使我可以轻松地混合 Pymunk 的物理建模(http://code.google.com/p/pymunk/)。

虽然它基于 OpenGL 并且您可以使用这些功能来实现特殊效果,但我在不了解它们的情况下也能做得很好。

它还可以与 py2exe 和 py2app 配合使用,这一点很重要,因为很多人没有安装 Python 解释器。

不利的一面是,由于它较新,因此网络上有关它的信息较少,可供查看的示例游戏也较少。

此外,它与以前的版本相比发生了很大的变化,因此一些教程现在已经过时了(有“新样式事件循环”
和 Sprite 类作为主要添加。)

我建议下载示例(其中包含一个名为 Astraea 的漂亮 Asteroids 克隆)并看看您是否喜欢这种风格。

I was considering both Pygame and Pyglet for a small 2D shooter, and after looking at source code and some tutorials went with Pyglet. I was very happy with the results.

Pyglet worked immediately and was enjoyable to work with, and conceptually very clean. It certainly had a Pythonic feel to me: you could get a straightforward and readable example going very quickly, and it uses decorators to good effect for event handling. It also didn't force a particular program structure, which made it easy for me to mix in the physics modelling of Pymunk (http://code.google.com/p/pymunk/).

While it is based on OpenGL and you can use those features for special effects, I was able to do just fine without any knowledge of them.

It also works well with py2exe and py2app, which is important because a lot of people do not have a Python interpreter installed.

On the downside, there is less information about it on the web because it is newer, as well as fewer sample games to look at.

Also, it changed quite a bit from previous versions, so some of the tutorials which are there are now out of date (there is the "new style event loop"
and the Sprite class as major additions.)

I would recommend downloading the examples (there is a nice Asteroids clone called Astraea included) and seeing if you like the style.

街角迷惘 2024-07-16 16:17:43

许可证:

  • Pygame:LGPL 许可证
  • Pyglet:BSD 许可证

库依赖项:

  • Pygame 严重依赖 SDL 库
  • Pyglet 是一个纯 Python 库,依赖项较少,我认为它需要更好地了解 OpenGL

社区:

  • Pygame 已经存在很长时间了,很多使用它的人
  • Pyglet 是一个新的库

受众:

  • Pygame 面向游戏开发(光标、精灵、操纵杆/游戏手柄支持)
  • Pyglet 更通用(尽管它有一个 Sprite 类)

我还发现了有关 pyglet-users 邮件的讨论列表:从 pygame+pyopengl 到 pyglet

免责声明:我还没有使用过,只尝试了一些教程;-)

License:

  • Pygame: LGPL license
  • Pyglet: BSD license

Library dependencies:

  • Pygame relies on SDL libraries heavily
  • Pyglet is a pure python library with fewer dependencies, I think it requires better understanding of OpenGL

Community:

  • Pygame is around here for a long time, a lot of people used it
  • Pyglet is a new lib

Audience:

  • Pygame is geared towards game development (cursors, sprites, joystick/gamepad support)
  • Pyglet is more general purpose (though it has a Sprite class)

I found also this discussion on pyglet-users mailing list: from pygame+pyopengl to pyglet

Disclaimer: I did not use either yet, only tried some tutorials ;-)

记忆里有你的影子 2024-07-16 16:17:43

如果您从不打算在游戏本身中绘制任何矢量图形或基元,而只是坚持从磁盘加载图像,那么 Pyglet 就很好(对于 2D 游戏)。 它也更干净,因为不需要编写自己的游戏循环,也不必担心速度、时间和响应能力。

然而,如果您必须动态生成图形,然后将它们保存为变量或文件,那么 pyglet 就会变得相当复杂,因为您必须开始处理低级 OpenGL 函数。 在这些场景中,pygame 凭借其软件渲染和 Surface 类更加用户友好。 或者您可以使用 Python 成像库并将其与 pyglet 连接。

显然,对于 3D 游戏,无论如何你都必须使用 OpenGL 函数,在这种情况下,我推荐 pyglet 而不是 pygame + PyOpenGL。

Pyglet is good (for 2D games) if you never intend to draw any vector graphics or primitives within the game itself, and just stick to loading images from disk. It's also much cleaner because there's no need to write your own game loop and have to worry about speed and timing and responsiveness.

However, if you ever have to generate graphics on-the-fly, and then save them, either as a variable or as a file, then pyglet becomes considerably more complicated because you start having to muck around with the low-level OpenGL functions. In those scenarios, pygame is much more user-friendly, with its software rendering and Surface class. Or you could use Python Imaging Library and interface it with pyglet.

Obviously, for 3D games, you are going to have to muck around with OpenGL functions anyway, in which case I recommend pyglet over pygame + PyOpenGL.

朕就是辣么酷 2024-07-16 16:17:43

我想补充一点,有一个快速的精灵库 Rabbyt 它可能是 Pyglet 的一个很好的补充。

I would like to add that there is a fast sprite library Rabbyt which may be a good complement for Pyglet.

陌路黄昏 2024-07-16 16:17:43

在查看了 pygame 和 pyglet 后,我​​发现 pyglet 更容易上手,并且能够在几天内编写一个简单的突破式游戏。

Having looked at both pygame and pyglet I found pyglet easier to pick up and was able to write a simple breakout style game within a few days.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文