-
-
Notifications
You must be signed in to change notification settings - Fork 934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MoveToEffect, RemoveEffect and SpeedEffectController not working inside SequenceEffect #2096
Comments
Ok, I can confirm the bug. If you use import 'package:doc_flame_examples/flower.dart';
import 'package:flame/effects.dart';
import 'package:flame/experimental.dart';
import 'package:flame/game.dart';
class SequenceEffectGame extends FlameGame with HasTappableComponents {
@override
Future<void> onLoad() async {
final flower = Flower(
size: 40,
position: canvasSize / 2,
onTap: (flower) {
flower.add(
SequenceEffect([
MoveEffect.to(
Vector2(30, 30),
SpeedEffectController(
LinearEffectController(1.0),
speed: 10.0,
),
),
RemoveEffect(delay: 1.0),
]),
);
},
);
add(flower);
}
}
|
Thanks for checking @munsterlander. It means there are probably 2 different bugs here: one with the RemoveEffect, and another with the MoveEffect. |
Well, I should add, the error is only with that controller. Other controllers work correctly - see the existing sequence effect live example. So I guess it could be with that controller on the effect? I have never really looked at how Edit: So yes, SequenceEffect([
MoveEffect.to(
Vector2(30, 30),
EffectController(duration: 1.0),
),
RemoveEffect(delay: 1.0),
]), |
[disclaimer: I am new to flutter] I traced into apply() of RemoveEffect which tries to remove it's parent. But when wrapped within SequenceEffect, its parent is not the component, but SequenceEffect itself. I'm not sure what would happen if there are more effects after RemoveEffect, though I'd believe they will just be ignored since SequenceEffect has been removed?
For now I just utilize the onComplete callback to remove the component manually. Not the best solution, but allow me to move on. |
You are completely correct @tksoh, it should be using |
Hey @spydon, I just saw that the mentioned @internal
double advance(double dt) {
final remainingDt = controller.advance(dt);//<--`advance()` executes first
if (!_started && controller.started) {
_started = true;
onStart();//<--then `onStart()` is executed
}
if (_started) {
final progress = controller.progress;
apply(progress);
_lastProgress = progress;
}
if (!_finished && controller.completed) {
_finished = true;
onFinish();
}
return remainingDt;
} So @internal
double advance(double dt) {
if (!_started && controller.started) {
_started = true;
onStart();//<--first `onStart()` is executed
}
final remainingDt = controller.advance(dt);//<--then `advance()` executes
if (_started) {
final progress = controller.progress;
apply(progress);
_lastProgress = progress;
}
if (!_finished && controller.completed) {
_finished = true;
onFinish();
}
return remainingDt;
} In fact, that's the order you use in the |
@pgirald good catch! Do you want to put up a PR for that? |
Current bug behaviour
When i put a
MoveToEffect
with aSpeedEffectController
and aLinearEffectController
and also aRemoveEffect
inside aSequenceEffect
, the component subject to them doesn´t move but instantly teleports to the desiredVector2
(regardless of whatspeed
i specify) and it doesn´t get removed from the game. If the Speed and LinearEffectController
's get replaced by aEffectController
object, the component does move in a trasition-like manner. Taking them out of theSequenceEffect
resolves all of the unexpected behaviours, regardless of what controller i use.Expected behaviour
Move the component to a desired
Vector2
in a timely manner and then removing it from the game.Steps to reproduce
Add a
SequenceEffect
containing aMoveToEffect
and aRemoveEffect
to aPositionComponent
in my case aCircleComponent
,use
SpeedEffectController
and aLinearEffectController
for theMoveToEffect
Flutter doctor output
More environment information
The text was updated successfully, but these errors were encountered: