PhysicsEngine class

Main physics engine class

Constructors

PhysicsEngine()
Create the best backend for the current platform.
factory
PhysicsEngine.pureDart()
Explicit pure-Dart backend constructor.

Properties

alpha double
Sub-frame interpolation alpha in [0, 1) for render-smooth positioning.
no setter
bodies List<PhysicsBody>
Get all bodies
no setter
debugRender bool
Whether debug rendering is enabled
getter/setter pair
gravity Vector2
Global gravity vector. Default: 981 units/s² (9.81 m/s² at 1 unit = 1 cm), matching the Box2D backend so both simulate identically.
final
hashCode int
The hash code for this object.
no setterinherited
joints List<JointConstraint>
All active joints (read-only view).
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stats Map<String, dynamic>
Lightweight physics diagnostics from the last simulation step.
no setter

Methods

addBody(PhysicsBody body) → void
Add a physics body
addDistanceJoint(PhysicsBody a, PhysicsBody b, {double? length, double? minLength, double? maxLength, double stiffness = 0.0, double damping = 0.3}) JointConstraint
addJoint(JointConstraint joint) → void
Add a joint constraint to the simulation.
addMouseJoint(PhysicsBody b, Vector2 target) JointConstraint
addPrismaticJoint(PhysicsBody a, PhysicsBody b, Offset axis) JointConstraint
addRevoluteJoint(PhysicsBody a, PhysicsBody b, Offset worldAnchor) JointConstraint
addWeldJoint(PhysicsBody a, PhysicsBody b) JointConstraint
cachePolygonShape(String cacheId, List<Offset> vertices) → void
castCircle(Offset origin, double radius, Offset motion, {Set<PhysicsBody>? exclude}) ShapeCastResult?
Sweep a circle of radius from origin by motion and return the first body hit, or null if nothing is in the way.
castRay(Ray ray, {Set<PhysicsBody>? exclude}) RayBodyHit?
Cast a ray and return the closest hit among all physics bodies.
castRayAll(Ray ray, {Set<PhysicsBody>? exclude}) List<RayBodyHit>
Cast a ray and return all hits sorted nearest-first.
dispose() → void
Clean up physics resources
getCachedPolygonShape(String cacheId) List<Offset>?
initialize() → void
Initialize the physics engine
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pollBodyMoveEvents(void fn(PhysicsBody body, {required bool fellAsleep})) → void
Iterate body-move events from the last step.
pollSensorBeginEvents(void fn(PhysicsBody a, PhysicsBody b)) → void
Iterate sensor-enter events from the last step.
pollSensorEndEvents(void fn(PhysicsBody a, PhysicsBody b)) → void
Iterate sensor-exit events from the last step.
queryAABB(Rect rect) List<PhysicsBody>
Return all active bodies whose bounding box overlaps rect.
queryCircle(Offset center, double radius) List<PhysicsBody>
Return all active bodies overlapping a circle at center with radius.
queryPoint(Offset point) List<PhysicsBody>
Return all active bodies containing point.
removeBody(PhysicsBody body) → void
Remove a physics body
removeJoint(JointConstraint joint) → void
Remove a joint constraint.
renderDebug(Canvas canvas, Size size) → void
Render debug visualization
setGravity(double gx, double gy) → void
Set world gravity, updating both the Dart gravity vector and any native simulation state. Override in backend-specific subclasses.
toString() String
A string representation of this object.
inherited
update(double deltaTime) → void
Update physics simulation

Operators

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