mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 19:12:31 +08:00
Working alternation of the effect sequence
This commit is contained in:
@ -20,8 +20,6 @@ void main() async {
|
||||
|
||||
class MyGame extends BaseGame with TapDetector {
|
||||
Square greenSquare;
|
||||
Square redSquare;
|
||||
Square orangeSquare;
|
||||
|
||||
MyGame() {
|
||||
final green = Paint()..color = const Color(0xAA338833);
|
||||
@ -33,7 +31,6 @@ class MyGame extends BaseGame with TapDetector {
|
||||
void onTapUp(TapUpDetails details) {
|
||||
final dx = details.localPosition.dx;
|
||||
final dy = details.localPosition.dy;
|
||||
|
||||
greenSquare.clearEffects();
|
||||
|
||||
final move1 = MoveEffect(
|
||||
@ -62,7 +59,7 @@ class MyGame extends BaseGame with TapDetector {
|
||||
|
||||
final rotate = RotateEffect(
|
||||
radians: (dx + dy) % pi,
|
||||
speed: 2.0, // Radians per second
|
||||
speed: 2.0,
|
||||
curve: Curves.decelerate,
|
||||
isInfinite: false,
|
||||
isAlternating: false,
|
||||
@ -70,8 +67,6 @@ class MyGame extends BaseGame with TapDetector {
|
||||
|
||||
final sequence = SequenceEffect(
|
||||
effects: [move1, scale, move2, rotate],
|
||||
//effects: [rotate],
|
||||
//effects: [scale],
|
||||
isInfinite: true, isAlternating: true);
|
||||
greenSquare.addEffect(sequence);
|
||||
}
|
||||
|
||||
@ -44,8 +44,6 @@ class MoveEffect extends PositionComponentEffect {
|
||||
_yDirection = _direction(destination.y, component.y);
|
||||
|
||||
final totalDistance = sqrt(pow(_xDistance, 2) + pow(_yDistance, 2));
|
||||
print(totalDistance);
|
||||
print(speed);
|
||||
travelTime = totalDistance / speed;
|
||||
}
|
||||
|
||||
|
||||
@ -40,7 +40,6 @@ class SequenceEffect extends PositionComponentEffect {
|
||||
});
|
||||
travelTime = effects.fold(0, (time, effect) => time + effect.travelTime *
|
||||
(effect.isAlternating ? 2 : 1));
|
||||
effects.forEach((element) {print("$element ${element.travelTime}");});
|
||||
component.setBySize(originalSize);
|
||||
component.setByPosition(originalPosition);
|
||||
_currentEffect = effects.first;
|
||||
@ -49,10 +48,10 @@ class SequenceEffect extends PositionComponentEffect {
|
||||
|
||||
@override
|
||||
void update(double dt) {
|
||||
super.update(dt);
|
||||
if (hasFinished()) {
|
||||
return;
|
||||
}
|
||||
super.update(dt);
|
||||
|
||||
_currentEffect.update(dt + _driftModifier);
|
||||
_driftModifier = 0.0;
|
||||
@ -61,20 +60,13 @@ class SequenceEffect extends PositionComponentEffect {
|
||||
_currentEffect.isAlternating = _currentWasAlternating;
|
||||
_currentIndex++;
|
||||
final iterationSize = isAlternating ? effects.length * 2 : effects.length;
|
||||
if (isInfinite &&
|
||||
_currentIndex != 0 &&
|
||||
_currentIndex % iterationSize == 0) {
|
||||
reset();
|
||||
if (_currentIndex != 0 && _currentIndex % iterationSize == 0) {
|
||||
isInfinite ? reset() : dispose();
|
||||
return;
|
||||
}
|
||||
final orderedEffects =
|
||||
curveDirection.isNegative ? effects.reversed.toList() : effects;
|
||||
_currentEffect = orderedEffects[_currentIndex % effects.length];
|
||||
print("Index: ${_currentIndex % effects.length}");
|
||||
print(_currentIndex);
|
||||
print(curveDirection);
|
||||
print(_currentEffect);
|
||||
print(orderedEffects);
|
||||
_currentWasAlternating = _currentEffect.isAlternating;
|
||||
if (isAlternating &&
|
||||
!_currentEffect.isAlternating &&
|
||||
@ -92,10 +84,4 @@ class SequenceEffect extends PositionComponentEffect {
|
||||
_currentIndex = 0;
|
||||
component = component;
|
||||
}
|
||||
|
||||
@override
|
||||
bool hasFinished() {
|
||||
return super.hasFinished() &&
|
||||
effects.every((effect) => effect.hasFinished());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user