World class

The simulation world: a container for bodies, shapes, and joints.

Wraps a native b2WorldId. Worlds are created up front and destroyed explicitly with destroy; destroying a world frees every body, shape, and joint in it.

A world must only be used from the isolate that created it.

Constructors

World({Vector2? gravity, WorldDef? definition})
Creates a world.

Properties

bodyMoveEvents → List<BodyMoveEvent>
The bodies that moved during the last step, with their new transforms.
no setter
contactEvents → ContactEvents
The contact events of the last step.
no setter
continuousEnabled ↔ bool
Whether continuous collision detection runs for fast bodies.
getter/setter pair
customFilterCallback ← bool Function(Shape shapeA, Shape shapeB)?
Sets or clears a custom collision filter, consulted for shape pairs that pass the regular category and group filtering. It returns whether the shapes may collide.
no getter
gravity ↔ Vector2
The gravity vector, in meters per second squared.
getter/setter pair
hashCode → int
The hash code for this object.
no setterinherited
isValid → bool
Whether this world has not been destroyed.
no setter
preSolveCallback ← bool Function(Shape shapeA, Shape shapeB, Vector2 normal)?
Sets or clears the pre-solve callback, invoked during step after a contact manifold is computed but before the solver runs. Returning false disables the contact for the step, enabling one-sided platforms and similar tricks.
no getter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
sensorEvents → SensorEvents
The sensor overlap events of the last step.
no setter
sleepingEnabled ↔ bool
Whether bodies in this world may fall asleep.
getter/setter pair

Methods

castRay(Vector2 origin, Vector2 translation, double callback(RayHit hit), {QueryFilter? filter}) → void
Casts a ray from origin along translation, invoking callback for every candidate hit in an arbitrary order.
castRayAll(Vector2 origin, Vector2 translation, {QueryFilter? filter}) → List<RayHit>
Casts a ray from origin along translation and returns every hit, sorted from nearest to farthest.
castRayClosest(Vector2 origin, Vector2 translation, {QueryFilter? filter}) → RayHit?
Casts a ray from origin along translation and returns the closest hit, or null when nothing is hit.
createBody([BodyDef? definition]) → Body
Creates a body in this world.
createDistanceJoint(DistanceJointDef definition) → DistanceJoint
Creates a distance joint from definition.
createFilterJoint(FilterJointDef definition) → FilterJoint
Creates a filter joint from definition, disabling collision between the two bodies.
createMotorJoint(MotorJointDef definition) → MotorJoint
Creates a motor joint from definition.
createMouseJoint(MouseJointDef definition) → MouseJoint
Creates a mouse joint from definition.
createPrismaticJoint(PrismaticJointDef definition) → PrismaticJoint
Creates a prismatic joint from definition.
createRevoluteJoint(RevoluteJointDef definition) → RevoluteJoint
Creates a revolute joint from definition.
createWeldJoint(WeldJointDef definition) → WeldJoint
Creates a weld joint from definition.
createWheelJoint(WheelJointDef definition) → WheelJoint
Creates a wheel joint from definition.
destroy() → void
Destroys this world and everything in it.
draw(DebugDraw debugDraw) → void
Draws the world's debug data into debugDraw.
explode(ExplosionDef definition) → void
Applies a radial explosion impulse to all shapes within reach.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
overlapAabb(Aabb aabb, {QueryFilter? filter}) → List<Shape>
Returns all shapes whose bounding boxes overlap aabb.
step(double timeStep, {int subStepCount = 4}) → void
Advances the simulation by timeStep seconds.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited