fix: flipper not fully locking (#175)

* fix: waited for game to unlock

* fix: flipper lock

Co-authored-by: Allison Ryan <allisonryan0002@gmail.com>
Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>
pull/260/head
Alejandro Santiago 3 years ago committed by GitHub
parent cf688f0f26
commit 61ed719bc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -55,7 +55,6 @@ class Flipper extends BodyComponent with KeyboardHandler, InitialPosition {
); );
final joint = _FlipperJoint(jointDef); final joint = _FlipperJoint(jointDef);
world.createJoint(joint); world.createJoint(joint);
unawaited(mounted.whenComplete(joint.unlock));
} }
List<FixtureDef> _createFixtureDefs() { List<FixtureDef> _createFixtureDefs() {
@ -132,6 +131,15 @@ class Flipper extends BodyComponent with KeyboardHandler, InitialPosition {
return body; return body;
} }
@override
void onMount() {
super.onMount();
gameRef.ready().whenComplete(
() => body.joints.whereType<_FlipperJoint>().first.unlock(),
);
}
} }
class _FlipperSpriteComponent extends SpriteComponent with HasGameRef { class _FlipperSpriteComponent extends SpriteComponent with HasGameRef {
@ -215,11 +223,8 @@ class _FlipperJoint extends RevoluteJoint {
/// The joint is locked when initialized in order to force the [Flipper] /// The joint is locked when initialized in order to force the [Flipper]
/// at its resting position. /// at its resting position.
void lock() { void lock() {
const angle = _halfSweepingAngle; final angle = _halfSweepingAngle * side.direction;
setLimits( setLimits(angle, angle);
angle * side.direction,
angle * side.direction,
);
} }
/// Unlocks the [Flipper] from its resting position. /// Unlocks the [Flipper] from its resting position.

Loading…
Cancel
Save