[英]AssertionError: The shape's body must be added to the space before (or at the same time) as the shape
I am trying to make a game, which includes polygons in pymunk, and to be able to do that in pymunk I decided to use many segments and draw it as a solid polygon.我正在尝试制作一个游戏,其中包含 pymunk 中的多边形,为了能够在 pymunk 中做到这一点,我决定使用许多段并将其绘制为实心多边形。 When I implement the code im getting an error当我执行代码时出现错误
My code我的代码
class StaticPoly:
def __init__(self, space, pos, elasticity=1, collision_type=None):
self.bodies = []
self.shapes = []
self.pos = pos
for i in list(range(0, len(self.pos) - 1))+[-1]:
print(i)
self.bodies.append(pymunk.Body(body_type=pymunk.Body.STATIC))
self.shapes.append(pymunk.Segment(self.bodies[i], self.pos[i], self.pos[i + 1], 1))
self.shapes[i].elasticity = elasticity
space.add(self.shapes[i])
if collision_type:
self.shapes[i].collision_type = collision_type
ERROR:错误:
Traceback (most recent call last):
File *path*, line 33, in <module>
catch = StaticPoly(space, ((0, 100), (100, 101), (0, 0)))
File *path again*, line 37, in __init__
space.add(self.shapes[i])
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymunk/space.py", line 401, in add
self._add_shape(o)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pymunk/space.py", line 441, in _add_shape
assert (
AssertionError: The shape's body must be added to the space before (or at the same time) as the shape.
StaticPoly.bodies
contains pymunk.Body
s. StaticPoly.bodies
包含pymunk.Body
s。 These bodies must also be added to the space.这些实体也必须添加到空间中。
Reed the error message: Reed 错误信息:
The shape's body must be added to the space before (or at the same time) as the shape.形状的主体必须在添加到形状之前(或同时)添加到空间中。
Either before无论是之前
space.add(self.bodies[i])
space.add(self.shapes[i])
or at the same time或同时
space.add(self.bodies[i], self.shapes[i])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.