From 079828a6f8da26bf9d8ec0372e6ccc7768f54f95 Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Sun, 4 Oct 2020 21:26:04 +0200 Subject: [PATCH] Use a list of vector2 for MoveEffect --- .../effects/sequence_effect/lib/main.dart | 9 +++++---- lib/effects/effects.dart | 2 +- lib/effects/move_effect.dart | 16 +++++++++++----- lib/effects/sequence_effect.dart | 18 ++++++++---------- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/doc/examples/effects/sequence_effect/lib/main.dart b/doc/examples/effects/sequence_effect/lib/main.dart index 857f41d2b..58d4baa14 100644 --- a/doc/examples/effects/sequence_effect/lib/main.dart +++ b/doc/examples/effects/sequence_effect/lib/main.dart @@ -72,14 +72,15 @@ class MyGame extends BaseGame with TapDetector { final combination = CombinedEffect( effects: [move2, rotate], - isAlternating: true, + isAlternating: false, + isInfinite: true, ); final sequence = SequenceEffect( effects: [move1, scale, combination], - isInfinite: false, - isAlternating: true, + isInfinite: true, + isAlternating: false, ); - greenSquare.addEffect(sequence); + greenSquare.addEffect(combination); } } diff --git a/lib/effects/effects.dart b/lib/effects/effects.dart index cb9f85423..4c793e2d0 100644 --- a/lib/effects/effects.dart +++ b/lib/effects/effects.dart @@ -60,7 +60,7 @@ abstract class PositionComponentEffect { if (isAlternating) { curveDirection = isMax() ? -1 : (isMin() ? 1 : curveDirection); } else if (isInfinite && isMax()) { - reset(); + currentTime = 0.0; } final driftMultiplier = (isAlternating && isMax() ? 2 : 1) * curveDirection; if (!hasFinished()) { diff --git a/lib/effects/move_effect.dart b/lib/effects/move_effect.dart index 9b328de5e..631367096 100644 --- a/lib/effects/move_effect.dart +++ b/lib/effects/move_effect.dart @@ -25,7 +25,6 @@ class MoveEffect extends PositionComponentEffect { double speed; Curve curve; Vector2 _startPosition; - Vector2 _peakPosition; MoveEffect({ @required this.path, @@ -61,10 +60,10 @@ class MoveEffect extends PositionComponentEffect { } else { _movePath = path; } - print(_movePath); - _peakPosition = isRelative ? path.last : path.last - _startPosition; if (!isAlternating) { - endPosition = _peakPosition; + endPosition = _movePath.last; + } else { + endPosition = _startPosition; } double pathLength = 0; @@ -91,9 +90,16 @@ class MoveEffect extends PositionComponentEffect { ); lastPosition = v; } - print(_percentagePath); travelTime = pathLength / speed; } + + @override + void reset() { + super.reset(); + if(_percentagePath?.isNotEmpty ?? false) { + _currentSubPath = _percentagePath.first; + } + } @override void update(double dt) { diff --git a/lib/effects/sequence_effect.dart b/lib/effects/sequence_effect.dart index eb7689906..66ed7c43a 100644 --- a/lib/effects/sequence_effect.dart +++ b/lib/effects/sequence_effect.dart @@ -63,9 +63,9 @@ class SequenceEffect extends PositionComponentEffect { _driftModifier = currentEffect.driftTime; _currentIndex++; final iterationSize = isAlternating ? effects.length * 2 : effects.length; - if (_currentIndex != 0 && - _currentIndex == iterationSize && - (currentEffect.isAlternating || + if (_currentIndex != 0 + && _currentIndex == iterationSize + && (currentEffect.isAlternating || currentEffect.isAlternating == isAlternating)) { isInfinite ? reset() : dispose(); return; @@ -92,12 +92,10 @@ class SequenceEffect extends PositionComponentEffect { @override void reset() { super.reset(); - effects.forEach((e) => e.reset()); - if (component != null) { - component.position = originalPosition; - component.angle = originalAngle; - component.size = originalSize; - initialize(component); - } + component.position = originalPosition; + component.angle = originalAngle; + component.size = originalSize; + initialize(component); + //effects.forEach((e) => e.reset()); } }