You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pinball/lib/game/components/anchor.dart

33 lines
758 B

import 'package:flame_forge2d/flame_forge2d.dart';
/// {@template anchor}
/// Non visual [BodyComponent] used to hold a [BodyType.dynamic] in [Joint]s
/// with this [BodyType.static].
///
/// It is recommended to [_position] the anchor first and then use the body
/// position as the anchor point when initializing a [JointDef].
///
/// ```dart
/// initialize(
/// dynamicBody.body,
/// anchor.body,
/// anchor.body.position,
/// );
/// ```
/// {@endtemplate}
class Anchor extends BodyComponent {
/// {@macro anchor}
Anchor({
required Vector2 position,
}) : _position = position;
final Vector2 _position;
@override
Body createBody() {
final bodyDef = BodyDef()..position = _position;
return world.createBody(bodyDef);
}
}