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
feat: Add isFirstFrame
and onStart
event to SpriteAnimation
#1492
Conversation
Not certain what format is off.... |
Just run |
Ran and updated. I am so used to that being ran in VS Code that I forgot to do it when I did all of this in Android Studio. |
@munsterlander would an API as #1552 solve your issue? For example, would adding a listener to the controller to check when it starts suffice? |
I'm not certain but at first glance, I don't think it would, at least not without additional code to determine where the animation is at. |
@munsterlander I believe you can listen to the value an determine where the animation is at. I'm on the phone right now but perhaps in the upcoming week I can provide some code to show that functionality. |
That's what I meant. I would need one listener with a switch statement and now would be math, i.e. animation.length-currentFrame==0 then it's the end, if it's 0 then the beginning and every where else in between. Currently, it's just clean defined callbacks. I mean the api route will work - not saying it won't - but it's more verbose and less intuitive. Ultimately, I will go which ever way you all want to go though. |
I will look into this, but wouldn't I'll soon make a sample code to actually see how the implementation would be. Then, if you don't mind, I'll ask for your feedback, since it's very helpful. Thanks a lot! |
For sure and I will gladly test. I can go either way, but I liked the callbacks because it was set and forget. With a listener, I need to have the switch statement for the current frame as compared to other values and this means my onStart and onComplete code is now comingled. That is where my fear of making things more complex vs what do we gain type issue. I really like single scope functions and not multi function but multifunction can be more versatile, so... |
@munsterlander what do you think of: _controller.addStatusListener((status) {
if (status == AnimationStatus.forward) {
// Started
} else if (status == AnimationStatus.completed) {
// Completed
}
}); I think you can also do: _controller.forward().whenComplete(...) Would the above work for your usecase? I think this suggested approach is more flexible and as you stated more versatile. For example, you can define the callbacks after the initialisation. A big advantage is that just by googling you can find good solutions since this is just how We could add Wdyt? |
I like the idea of having
Simply call the |
There are no asynchronous operations involved here so you don't have to worry about the order. For test number 3 you can run small increments in update to see that the first increment that overlaps the frame triggers the callback (and not the last). It looks like it actually triggers in the end of the frame now, so you'd have to call the callback for the next index (wrapped with modulo if the animation should repeat) in the while-loop, and the callback for the first frame has to be done together with the |
Good idea!
I think a more reliable approach is to call |
I moved the Edit: @spydon and @st-pasha I just want to confirm with you that |
Almost, you also have to pass the step to test('verify call is being made at the first of the frame for multi-frame animation', () {
var timePassed = 0.0;
var dt = 0.5;
var timesCalled = 0;
final sprite = MockSprite();
final spriteList = [sprite, sprite, sprite];
final animation = SpriteAnimation.spriteList(spriteList, stepTime: 1, loop: false);
animation.onFrame = (index) {
expect(index, timePassed);
timesCalled++
};
while(step <= 3){
timePassed += dt;
animation.update(dt);
}
expect(timeCalled, spriteList.length);
});
Yes,
This is due to the change that was merged in #1564, do you need help sorting out the conflict? |
…t at beginning of frame.
@spydon Here is what ended up passing:
Other tests were corrected. I will now work on resolving the conflict. Its a simple conflict, but git isn't fetching the change, so I just need to see why. |
…me-engine-main # Conflicts: # packages/flame/test/sprite_animation_test.dart
Co-authored-by: Pasha Stetsenko <stpasha@gmail.com>
Co-authored-by: Pasha Stetsenko <stpasha@gmail.com>
Co-authored-by: Pasha Stetsenko <stpasha@gmail.com>
…me-engine-main # Conflicts: # packages/flame/test/sprite_animation_test.dart
Why do you have |
Thats what we are discussing here: #1492 (comment) |
You can run |
This thing is annoying. I ran it, committed and pushed, then melos says lines over 80, so I go correct those, re run it, commit, but something else pops up after push. I have rerun it, commited and pushed again, lol. Quick question on that though, do you manually run that command or do you let Android Studio (if you use that) do its reformat code before commit? |
I let android studio auto format. Maybe you don't have the newest version of flutter? Then the formatting can differ, run |
I do. Not certain, but I found this and will check it shortly. https://stackoverflow.com/questions/27092772/auto-code-formatting-in-android-studio Edit: Format code on save was not checked. I have checked that now and will see how it goes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! You put a lot of time into this feature, very appreciated. :)
Description
This adds
isFirstFrame
andonStart
event callback tosprite_animation.dart
. May not be useful for everyone but I needed to trigger another event whenever an animation was called as multiple factors could trigger that animation.Checklist
fix:
,feat:
,docs:
etc).docs
and added dartdoc comments with///
.examples
.Breaking Change