Forge2DGame<T extends Forge2DWorld> constructor
- Forge2DWorld? world,
- CameraComponent? camera,
- Vector2? gravity,
- ContactEventsDispatcher? contactEventsDispatcher,
- double metersToPixels = Forge2DViewfinder.defaultMetersToPixels,
- double? lengthUnitsPerMeter,
Creates a game with a Forge2DWorld.
The world is measured in meters and rendered with metersToPixels
pixels per meter, see Forge2DViewfinder. If you pass your own camera
its viewfinder is replaced with a Forge2DViewfinder, unless it already
is one, in which case metersToPixels is applied to it.
lengthUnitsPerMeter tells Forge2D that the world is laid out in units
where one meter is that many of them, which scales the tolerances that
Box2D expresses as absolute lengths. Lay the world out so that moving
bodies are roughly 0.1 to 10 meters instead when you can; see
Tolerances and the lengthUnitsPerMeter argument of
initializeForge2D, which this is forwarded to.
contactEventsDispatcher is only used for the world that this
constructor creates, so pass it to the Forge2DWorld itself when you
provide a world.
Implementation
Forge2DGame({
Forge2DWorld? world,
CameraComponent? camera,
Vector2? gravity,
ContactEventsDispatcher? contactEventsDispatcher,
double metersToPixels = Forge2DViewfinder.defaultMetersToPixels,
this.lengthUnitsPerMeter,
}) : assert(
world == null || contactEventsDispatcher == null,
'contactEventsDispatcher is ignored when a world is provided, pass '
'it to the Forge2DWorld constructor instead',
),
super(
world:
((world?..gravity = gravity ?? world.gravity) ??
Forge2DWorld(
gravity: gravity,
contactEventsDispatcher: contactEventsDispatcher,
))
as T,
camera: camera ?? CameraComponent(),
) {
final viewfinder = this.camera.viewfinder;
if (viewfinder is Forge2DViewfinder) {
viewfinder.metersToPixels = metersToPixels;
} else {
this.camera.viewfinder = Forge2DViewfinder(
metersToPixels: metersToPixels,
);
}
}