From 51715d304f453132ef8f1589c2107adfc44d9070 Mon Sep 17 00:00:00 2001 From: Viktor Lidholt Date: Tue, 25 Aug 2015 09:27:39 -0700 Subject: [PATCH] Adds base rotation property to rotate-to-movement constraint --- examples/game/lib/constraint.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/game/lib/constraint.dart b/examples/game/lib/constraint.dart index d1d3a82b24..9909ba84a5 100644 --- a/examples/game/lib/constraint.dart +++ b/examples/game/lib/constraint.dart @@ -17,8 +17,9 @@ double _dampenRotation(double src, double dst, double dampening) { } class ConstraintRotationToMovement { - ConstraintRotationToMovement([this.dampening]); + ConstraintRotationToMovement([this.baseRotation = 0.0, this.dampening]); final double dampening; + final double baseRotation; Point _lastPosition; @@ -27,12 +28,12 @@ class ConstraintRotationToMovement { } void constrain(Node node, double dt) { - assert(_lastPosition != null); + if (_lastPosition == null) return; if (_lastPosition == node.position) return; // Get the target angle Offset offset = node.position - _lastPosition; - double target = degrees(GameMath.atan2(offset.dy, offset.dx)); + double target = degrees(GameMath.atan2(offset.dy, offset.dx)) + baseRotation; if (dampening == null) node.rotation = target;