AssertionError: The shape's body must be added to the space before (or at the same time) as the shape
AssertionError: The shape's body must be added to the space before (or at the same time) as the shape
我正在尝试制作一个游戏,其中包括 pymunk 中的多边形,为了能够在 pymunk 中做到这一点,我决定使用许多线段并将其绘制为实心多边形。当我执行代码时出现错误
我的代码
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
错误:
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
包含 pymunk.Body
。这些机构也必须添加到 space.
重复错误消息:
The shape's body must be added to the space before (or at the same time) as the shape.
之前
space.add(self.bodies[i])
space.add(self.shapes[i])
或同时
space.add(self.bodies[i], self.shapes[i])
我正在尝试制作一个游戏,其中包括 pymunk 中的多边形,为了能够在 pymunk 中做到这一点,我决定使用许多线段并将其绘制为实心多边形。当我执行代码时出现错误
我的代码
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
错误:
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
包含 pymunk.Body
。这些机构也必须添加到 space.
重复错误消息:
The shape's body must be added to the space before (or at the same time) as the shape.
之前
space.add(self.bodies[i])
space.add(self.shapes[i])
或同时
space.add(self.bodies[i], self.shapes[i])