Shape Module
This module defines high-level shape objects for Box2D. Each shape’s constructor now accepts a body and a shape definition. Each shape (except Chain) subclasses a common base that implements common properties. Each shape also has a classmethod “create” that matches the signature from before. Chain is now implemented as a separate class.
- class box2d.shape.Box(body, shapedef)[source]
A box (rectangle) shape that can be attached to a body. Inherits from Polygon since a box is a special case of a convex polygon.
- class box2d.shape.Chain(body, shapedef)[source]
A chain shape that can be attached to a body. Chain shapes are not a subclass of Shape and do not have the common shape methods because they are typically used for static boundaries and have no density/sensor properties.
- property body
Return the body this chain is attached to.
- class box2d.shape.Polygon(body, shapedef)[source]
A convex polygon shape that can be attached to a body.
- class box2d.shape.Segment(body, shapedef)[source]
A line segment shape that can be attached to a body.
- class box2d.shape.Shape(body, shapedef)[source]
Base class for all non-chain shapes. Its constructor now accepts only a body and a shape definition. It provides common properties like density, friction, restitution, and a helper _finalize.
- property body
Return the body to which this shape is attached.
- property density
Get the mass density of the shape.
- property friction
Get the friction coefficient of the shape.
- property is_sensor
Check if this shape is a sensor.
- property restitution
Get the restitution (bounciness) of the shape.