I'm making a simple 2D game where I need to reuse a spriteAnimationComponent multiple times. But I need to remove it first and upon removing it, I need the animation component's frame to be reset to the first frame, so that everytime it is reused, it will start at the first frame.
How do I do that?
I thought it was strange that we didn't have this built-in, so I created a PR for this, where you can simply set resetOnRemove: true
:
SpriteAnimationComponent(
...
resetOnRemove: true,
);
Until that is released (in a few days), you can do this by listening to the removed
future:
component.removed.then((_) {
component.animationTicker?.reset();
});
or override onRemove
:
@override
void onRemove() {
super.onRemove();
if (resetOnRemove) {
_animationTicker?.reset();
}
}