fix: waited for game to unlock

pull/175/head
alestiago 4 years ago
parent 0bec997178
commit db51c147b0

@ -52,7 +52,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() {
@ -127,6 +126,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 {
@ -207,11 +215,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