mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 19:12:31 +08:00
Use a list of vector2 for MoveEffect
This commit is contained in:
committed by
Lukas Klingsbo
parent
6432f00a60
commit
079828a6f8
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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()) {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user