mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 20:36: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(
|
final combination = CombinedEffect(
|
||||||
effects: [move2, rotate],
|
effects: [move2, rotate],
|
||||||
isAlternating: true,
|
isAlternating: false,
|
||||||
|
isInfinite: true,
|
||||||
);
|
);
|
||||||
|
|
||||||
final sequence = SequenceEffect(
|
final sequence = SequenceEffect(
|
||||||
effects: [move1, scale, combination],
|
effects: [move1, scale, combination],
|
||||||
isInfinite: false,
|
isInfinite: true,
|
||||||
isAlternating: true,
|
isAlternating: false,
|
||||||
);
|
);
|
||||||
greenSquare.addEffect(sequence);
|
greenSquare.addEffect(combination);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,7 +60,7 @@ abstract class PositionComponentEffect {
|
|||||||
if (isAlternating) {
|
if (isAlternating) {
|
||||||
curveDirection = isMax() ? -1 : (isMin() ? 1 : curveDirection);
|
curveDirection = isMax() ? -1 : (isMin() ? 1 : curveDirection);
|
||||||
} else if (isInfinite && isMax()) {
|
} else if (isInfinite && isMax()) {
|
||||||
reset();
|
currentTime = 0.0;
|
||||||
}
|
}
|
||||||
final driftMultiplier = (isAlternating && isMax() ? 2 : 1) * curveDirection;
|
final driftMultiplier = (isAlternating && isMax() ? 2 : 1) * curveDirection;
|
||||||
if (!hasFinished()) {
|
if (!hasFinished()) {
|
||||||
|
|||||||
@ -25,7 +25,6 @@ class MoveEffect extends PositionComponentEffect {
|
|||||||
double speed;
|
double speed;
|
||||||
Curve curve;
|
Curve curve;
|
||||||
Vector2 _startPosition;
|
Vector2 _startPosition;
|
||||||
Vector2 _peakPosition;
|
|
||||||
|
|
||||||
MoveEffect({
|
MoveEffect({
|
||||||
@required this.path,
|
@required this.path,
|
||||||
@ -61,10 +60,10 @@ class MoveEffect extends PositionComponentEffect {
|
|||||||
} else {
|
} else {
|
||||||
_movePath = path;
|
_movePath = path;
|
||||||
}
|
}
|
||||||
print(_movePath);
|
|
||||||
_peakPosition = isRelative ? path.last : path.last - _startPosition;
|
|
||||||
if (!isAlternating) {
|
if (!isAlternating) {
|
||||||
endPosition = _peakPosition;
|
endPosition = _movePath.last;
|
||||||
|
} else {
|
||||||
|
endPosition = _startPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
double pathLength = 0;
|
double pathLength = 0;
|
||||||
@ -91,10 +90,17 @@ class MoveEffect extends PositionComponentEffect {
|
|||||||
);
|
);
|
||||||
lastPosition = v;
|
lastPosition = v;
|
||||||
}
|
}
|
||||||
print(_percentagePath);
|
|
||||||
travelTime = pathLength / speed;
|
travelTime = pathLength / speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void reset() {
|
||||||
|
super.reset();
|
||||||
|
if(_percentagePath?.isNotEmpty ?? false) {
|
||||||
|
_currentSubPath = _percentagePath.first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void update(double dt) {
|
void update(double dt) {
|
||||||
if (hasFinished()) {
|
if (hasFinished()) {
|
||||||
|
|||||||
@ -63,9 +63,9 @@ class SequenceEffect extends PositionComponentEffect {
|
|||||||
_driftModifier = currentEffect.driftTime;
|
_driftModifier = currentEffect.driftTime;
|
||||||
_currentIndex++;
|
_currentIndex++;
|
||||||
final iterationSize = isAlternating ? effects.length * 2 : effects.length;
|
final iterationSize = isAlternating ? effects.length * 2 : effects.length;
|
||||||
if (_currentIndex != 0 &&
|
if (_currentIndex != 0
|
||||||
_currentIndex == iterationSize &&
|
&& _currentIndex == iterationSize
|
||||||
(currentEffect.isAlternating ||
|
&& (currentEffect.isAlternating ||
|
||||||
currentEffect.isAlternating == isAlternating)) {
|
currentEffect.isAlternating == isAlternating)) {
|
||||||
isInfinite ? reset() : dispose();
|
isInfinite ? reset() : dispose();
|
||||||
return;
|
return;
|
||||||
@ -92,12 +92,10 @@ class SequenceEffect extends PositionComponentEffect {
|
|||||||
@override
|
@override
|
||||||
void reset() {
|
void reset() {
|
||||||
super.reset();
|
super.reset();
|
||||||
effects.forEach((e) => e.reset());
|
|
||||||
if (component != null) {
|
|
||||||
component.position = originalPosition;
|
component.position = originalPosition;
|
||||||
component.angle = originalAngle;
|
component.angle = originalAngle;
|
||||||
component.size = originalSize;
|
component.size = originalSize;
|
||||||
initialize(component);
|
initialize(component);
|
||||||
}
|
//effects.forEach((e) => e.reset());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user