-
Notifications
You must be signed in to change notification settings - Fork 191
Open
Description
The copy of a body attached to multiple shapes raises an AssertionError: The shape's body must be added to the space before (or at the same time) as the shape. when following the usage shown in the examples.
The only workaround I have found is to get a new body and only copy the shapes (see below).
import pymunk
s = pymunk.Space()
b1 = pymunk.Body(1, 1)
b1.position = 1, 2
shape1 = pymunk.Circle(b1, 4)
shape2 = pymunk.Circle(b1, 6)
s.add(b1, shape1, shape2)
# Work, with a new object
b2 = pymunk.Body()
shape_copies = []
for shape in b1.shapes:
shape_copies.append(shape.copy())
shape_copies[-1].body = b2
s.add(*shape_copies, b2)
# Do not work
b3 = b1.copy()
shape_copies = []
for shape in b1.shapes:
shape_copies.append(shape.copy())
s.add(*shape_copies, b3)
# Do not work
shape_copies = []
for shape in b1.shapes:
shape_copies.append(shape.copy())
s.add(*shape_copies, shape_copies[0].body)xiaohongzsy
Metadata
Metadata
Assignees
Labels
No labels