简体   繁体   English

断言错误:必须在形状之前(或同时)将形状的主体添加到空间中

[英]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.

相关问题 AssertionError:传入张量形状必须为4-D - AssertionError: Incoming Tensor shape must be 4-D ValueError:条件数组必须与自身的形状相同 - ValueError: Array conditional must be same shape as self ValueError:块和形状必须具有相同的长度/尺寸 - ValueError: Chunks and shape must be of the same length/dimension “ValueError:条件数组必须与自身形状相同” - "ValueError: Array conditional must be same shape as self" 数组条件必须与自身的形状相同 - Array conditional must be same shape as self 如果单词在字符串的开头或在一个或多个空格之后,则在单词之后添加一个空格,同时它必须在结尾或之前 \n - Add a space after a word if it's at the beginning of a string or if it's after one or more spaces, and at the same time it must be at end or before \n ValueError:形状不匹配:形状相同 - ValueError: shape mismatch: with same shape logits 和 labels 必须具有相同的第一维,得到 logits 形状 [2048,10] 和标签形状 [32] - logits and labels must have the same first dimension, got logits shape [2048,10] and labels shape [32] InvalidArgumentError:logits 和标签必须具有相同的第一维,得到 logits 形状 [15488,3] 和标签形状 [32] - InvalidArgumentError: logits and labels must have the same first dimension, got logits shape [15488,3] and labels shape [32] TensorFlow:logits 和标签必须具有相同的第一维,得到 logits 形状 [120,4] 和标签形状 [480] - TensorFlow: logits and labels must have the same first dimension, got logits shape [120,4] and labels shape [480]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM