flame icon indicating copy to clipboard operation
flame copied to clipboard

Add on complete callback to SpriteAnimationWidget

Open erickzanardo opened this issue 3 years ago • 8 comments

Problem to solve

there is no easy way to know if an animation is finished when using it through SpriteAnimationWidget since it don't exposes a callback and internally it overrides any set callback on animation.onComplete

Proposal

Provide a callback on the widget constructor so the user can register the callback.

More information

erickzanardo avatar Apr 13 '22 12:04 erickzanardo

I need to have a closer look but perhaps having a Controller would be closer to the ideal solution. Perhaps we can reuse the controller.

Another idea could be to expose the playing and listen when this value changes to false from true. Then, a setter for this could be used to, for example if we want the animation to be paused.

Anyways, this is just me naively dropping some ideas. I need to have a closer look at the actual code 👨‍💻

Hope it helps.

alestiago avatar Apr 15 '22 14:04 alestiago

@alestiago I think it is important that it should be similar to the rest of our APIs, so passing in a callback I think would be the optimal solution. :)

spydon avatar Apr 15 '22 15:04 spydon

@alestiago I think it is important that it should be similar to the rest of our APIs, so passing in a callback I think would be the optimal solution. :)

Forgot that this is the widget, I guess it should be as Fluttery as possible instead then.

spydon avatar Apr 16 '22 07:04 spydon

I'll be soon raising a PR so that we can discuss how the API of this Widget should be from seeing some code.

alestiago avatar Apr 16 '22 09:04 alestiago

@erickzanardo does https://github.com/flame-engine/flame/pull/1564 solve this issue?

alestiago avatar May 03 '22 16:05 alestiago

@erickzanardo does #1564 solve this issue?

Humm, I think it offers an alternative, but a callback on the widget would be more straight forward and better for users.

erickzanardo avatar May 03 '22 16:05 erickzanardo

Doesn't animation.completed.whenComplete(callback) allow using a callback?

alestiago avatar May 03 '22 16:05 alestiago

Doesn't animation.completed.whenComplete(callback) allow using a callback?

Yes, but that means that you need to hold an animation instance, which will probably require the use of a stateful widget.

SpriteAnimationWidget has some helper constructors that loads and manages the animation instance for you. So a callback received by the SpriteAnimationWidget would be the best.

We could even use the animation.completed internally to hook that callback that we would receive

erickzanardo avatar May 03 '22 16:05 erickzanardo