Correct drift modifier for when effect is finished

This commit is contained in:
Lukas Klingsbo
2020-06-05 22:18:44 +02:00
parent 4b16046367
commit fc67a61168

View File

@ -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;
}