ContactCallbacks class mixin

Used to listen to a BodyComponent's contact events.

Contact events occur whenever two Shapes meet each other.

To react to contacts you should assign ContactCallbacks to a Body's userData or/and to a Shape's userData. If the Body userData is set to a ContactCallbacks the contact events of this will be called when any of the body's Shapes contacts another Shape.

If instead you wish to be more specific and only trigger contact events when a specific Shape contacts another Shape, you can set the shape's userData to a ContactCallbacks.

If the colliding Shape userData and Body userData are null, then the contact events are not called.

Forge2D only reports events for shapes that have opted in to them, so remember to set ShapeDef.enableContactEvents (and ShapeDef.enableSensorEvents for sensors and their visitors) on the shapes that should generate events. The default BodyComponent.createBody implementation enables them automatically when a ContactCallbacks is present in the body's or shape's userData.

The described behavior is a simple out of the box solution to propagate contact events. If you wish to implement your own logic you can subclass ContactEventsDispatcher and provide it to your Forge2DGame or Forge2DWorld.

The old preSolve and postSolve callbacks no longer exist in Forge2D. To disable contacts before they are solved, set Forge2DWorld.preSolveCallback (and ShapeDef.enablePreSolveEvents on the involved shapes). To measure impact strength, enable ShapeDef.enableHitEvents and poll the world's contactEvents.hit.

Constructors

ContactCallbacks()

Properties

hashCode int
The hash code for this object.
no setterinherited
onBeginContact ↔ void Function(Object other, Contact contact)?
getter/setter pair
onEndContact ↔ void Function(Object other, Contact contact)?
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

beginContact(Object other, Contact contact) → void
Called when two Shapes start being in contact.
endContact(Object other, Contact contact) → void
Called when two Shapes cease being in contact.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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