Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Body.copy() with multiple shapes attached to a body #239

Open
@GuillaumeBroggi

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /