Differences between Python game libraries Pygame and Pyglet?

五迷三道 提交于 2019-11-29 19:05:58

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.

sastanin

Pygame: LGPL license

Pyglet: BSD license

Pygame relies on SDL libraries heavily

Pyglet is a pure python library with fewer dependencies, I think it requires better understanding of OpenGL

Pygame is around here for a long time, a lot of people used it

Pyglet is a new lib

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 ;-)

ztangent

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.

I would like to add that there is a fast sprite library Rabbyt which may be a good complement for 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!