Skip to content
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

[Feature Request] Add Status Listener and Animation Status #147

Open
gctommy opened this issue Sep 3, 2019 · 2 comments
Open

[Feature Request] Add Status Listener and Animation Status #147

gctommy opened this issue Sep 3, 2019 · 2 comments
Assignees

Comments

@gctommy
Copy link

gctommy commented Sep 3, 2019

I currently have to do something like this to increment an interval when the animation duration reaches/passes the Actor's duration—so do something when the animation completes one loop:

_duration += elapsed * _speed;
// ...
if (double.parse(_duration.toStringAsFixed(2)) >= double.parse(_actor.duration.toStringAsFixed(2))) {
    interval++;
    _duration = 0.0;
}

It would be easier if one could use a controller that has an addStatusListener listening for an AnimationStatus of completed and isAnimating?

@luigi-rosso
Copy link
Contributor

This is a good idea.

On some other platforms we have the concept of AnimationInstance which tracks time for the animation and can report when the animation completes/loops (and has a callback for elapsed events that can trigger on the timeline). We could add something like that which you can use in your FlareController.

Some pseudo-ish code follows...

FlareControls could then return the animationInstance:

AnimationInstance animation = flareControls.play("someAnimation");
animation.onComplete(() { ... });
animation.onLoop(() { ... });

Or what you're suggesting:

class AnimationListener {
  void onLoop(AnimationInstance instance);
  void onComplete(AnimationInstance instance);
  void onMixedIn(AnimationInstance instance);
}
AnimationInstance animation = flareControls.play("someAnimation");
animation.addListener(myListener);

You could also use AnimationInstance directly in a FlareController:

class MyController extends FlareController {
  AnimationInstance someAnimation;
  @override
  void initialize(FlutterActorArtboard artboard) {
    // new artboard method to create an instance
    someAnimation = artboard.getAnimationInstance("someAnimation"); 
  }

  @override
  bool advance(FlutterActorArtboard artboard, double elapsed) {
    super.advance(artboard, elapsed);
    // internally will invoke listeners
    someAnimation.advance(elapsed);
    // apply doesn't need time and mix as the instance holds these internally
    someAnimation.apply(artboard);
  }
}

Curious to hear what people would prefer/find more flexible/fits the platform best.

@luigi-rosso luigi-rosso self-assigned this Sep 4, 2019
@stx
Copy link

stx commented Sep 5, 2019

AnimationInstance animation = flareControls.play("someAnimation");
animation.onComplete(() { ... });
animation.onLoop(() { ... });

This feels pretty great with Flutter, IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants