我正在努力学习PyMunk库,我使用了他们的网站上的例子。这是一个代码:
import pymunk # Import pymunk..
space = pymunk.Space() # Create a Space which contain the simulation
space.gravity = 0,-1000 # Set its gravity
body = pymunk.Body(1,1666) # Create a Body with mass and moment
body.position = 50,100 # Set the position of the body
poly = pymunk.Poly.create_box(body) # Create a box shape and attach to body
space.add(body, poly) # Add both body and shape to the simulation
while True: # Infinite loop simulation
space.step(0.02) # Step the simulation one step forward当我运行它时,窗口不会出现,而且在CMD中它写着:Loading chipmunk for Windows (64bit) [C:\Users\Theo\AppData\Local\Programs\Python\Python35\lib\site-packages\pymunk\chipmunk.dll],不加载任何东西。我等了一个小时。有什么问题吗?
发布于 2017-08-27 22:53:52
您应该尝试将PyMunk与PyGame或PyGlet连接起来,以便能够通过窗口使任何结果具有活力。请参阅这里的更多内容:http://www.pymunk.org/en/latest/
发布于 2020-01-29 03:12:36
我也有一个惊人的惊喜,试图运行演示。
所以,就像@Teodor说的,除非连接可视化库,否则基本演示不会绘制任何东西。这些都是可选的,如文档中所述:PyGame和PyGlet。
这段代码不会尝试打开一个窗口,但是如果您添加了一个print语句,您将看到它确实“移动”:
while True:
space.step(0.02)
print(body.position) # add this line您可以查看这些视频教程来插入Pyglet (但要以1.5x的速度观看它们.):
Pyglet的基本演示如下所示:
import pymunk
import pyglet
from pymunk.pyglet_util import DrawOptions
options = DrawOptions()
window = pyglet.window.Window(800, 600, "Brackets")
space = pymunk.Space()
space.gravity = (0, -1000)
body = pymunk.Body(1, 1666)
body.position = 400, 500
poly = pymunk.Poly.create_box(body, size=(100, 20))
space.add(body, poly)
# from here, the rest of the code is the render loop
@window.event
def on_draw():
window.clear()
space.debug_draw(options)
def update(dt):
space.step(dt) # Step the simulation one step forward
pyglet.clock.schedule_interval(update, 1.0 / 60)
pyglet.app.run()另外,下载Pymunk示例文件夹并试用它们。他们中的一些人使用小矮人,一些玩偶游戏。
https://github.com/viblo/pymunk/tree/master/examples
Pyglet也有一个示例文件夹,因此您可以看到它的工作也是孤立的:
https://stackoverflow.com/questions/45907653
复制相似问题