From fc67a611689590e3510c369a233e5b9480fa6ec7 Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Fri, 5 Jun 2020 22:18:44 +0200 Subject: [PATCH] Correct drift modifier for when effect is finished --- lib/effects/effects.dart | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/effects/effects.dart b/lib/effects/effects.dart index 94074d9a4..f41425ae1 100644 --- a/lib/effects/effects.dart +++ b/lib/effects/effects.dart @@ -43,19 +43,24 @@ abstract class PositionComponentEffect { } void update(double dt) { + _updateDriftTime(); if (isAlternating) { curveDirection = isMax() ? -1 : (isMin() ? 1 : curveDirection); } else if (isInfinite && isMax()) { currentTime = 0.0; } - _updateDriftTime(); - currentTime += dt * curveDirection - driftTime; - percentage = min(1.0, max(0.0, currentTime / travelTime)); + final driftMultiplier = (isAlternating && isMax() ? 2 : 1) * curveDirection; + if (!hasFinished()) { + currentTime += dt * curveDirection + driftTime * driftMultiplier; + percentage = min(1.0, max(0.0, currentTime / travelTime)); + } } @mustCallSuper void initialize(PositionComponent _comp) { component = _comp; + /// You need to set the travelTime during the initialization of the + /// extending effect travelTime = null; /// If these aren't modified by the extending effect it is assumed that the /// effect didn't bring the component to another state than the one it @@ -87,10 +92,10 @@ abstract class PositionComponentEffect { } void _updateDriftTime() { - if ((isInfinite || isAlternating) && isMax()) { - driftTime = (currentTime - travelTime) * (isAlternating ? 2 : -1); - } else if (isInfinite && isAlternating && isMin()) { - driftTime = currentTime; + if (isMax()) { + driftTime = currentTime - travelTime; + } else if (isMin()) { + driftTime = currentTime.abs(); } else { driftTime = 0; }