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

Feat/alternative animation queuing mechanism #16

Open
wants to merge 2 commits into
base: custom_animation_engine
Choose a base branch
from

Conversation

riobah
Copy link
Contributor

@riobah riobah commented Sep 6, 2017

This PR is adding an alternative animation queuing system while keeping the existing code for backward compatibility.

Benefits compared to the existing mechanism:

  • Ability to queue multiple animations
  • Ability to wait till the end of the existing animation before starting the queued animation
  • Ability to continue an animation infinitely running (like walking) and inserting one single animation in between its executions
  • Simplified endOfAnimation: method implementation.

Old code is kept as it is. If we agree that the new code is supporting the existing functions of the code, we can clean the old code later providing the same interface for backward compatibility.

…tiple animations to be queued and the actully running one not being cancelled with an enqueue.

The legacy code is kept as it is to provide backward compability
@mredig
Copy link
Owner

mredig commented Sep 6, 2017 via email

@riobah
Copy link
Contributor Author

riobah commented Sep 6, 2017

No worries Michael. Feel free to check them anytime you are available. Appreciate your message.

@mredig
Copy link
Owner

mredig commented Sep 7, 2017

I will have to review this PR in more depth later. Right now, I'm failing to see the distinguishment from the original.

Feel free to provide an example comparison to help speed things up, otherwise I'll get this this when I can.

Thanks!

@riobah
Copy link
Contributor Author

riobah commented Sep 7, 2017

Thank you Michael. I'm quite new to the code base, so I hope I'm not reaching to wrong conclusions because of my mis-usage of the library.

Below was my understanding:

  1. While I have a queued animation (say "walk") and I call runAnimation method, it stops the already running animation instantly.
                [boy runAnimation:@"walk" andCount:-1 withIntroPeriodOf:0 andUseQueue:YES];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [boy runAnimation:@"jump" andCount:1];         // jump once, and then continue walking
                });

It does not let the current cycle to reach to the end, because of the following code in runAnimation method.

 if  (self.isRunningAnimation) {
        [self stopAnimation]; //clear any current animations
 }

PR allows the new animation to be added to the queue and run after the existing animation's cycle ends.

  1. I haven't dig to find the root cause, but with the following code boy jumps twice:
                [boy runAnimation:@"walk" andCount:-1 withIntroPeriodOf:0 andUseQueue:YES];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [boy runAnimation:@"jump" andCount:1];         // jump once, and then continue walking
                });
  1. With the queue mechanism, I was expecting to be able to queue multiple animations with seperate runAnimation method call. I see existing code is not working like this, and PR is adding this functionality. Assume with each tap of the user we add one jump animation to the queue, even if the jump animation is still in progress.

As an example, below code does not result with two jumps:

                [boy runAnimation:@"walk" andCount:-1 withIntroPeriodOf:0 andUseQueue:YES];

                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [boy runAnimation:@"jump" andCount:1 withIntroPeriodOf:0 andUseQueue:YES];
                    [boy runAnimation:@"walk" andCount:1 withIntroPeriodOf:0 andUseQueue:YES]; 
                    [boy runAnimation:@"jump" andCount:1 withIntroPeriodOf:0 andUseQueue:YES];
                });

Again, I might be wrong with my conclusion as I'm pretty new to the library. Any comment is quite welcomed.

Thank you again for considering the PR.

@riobah
Copy link
Contributor Author

riobah commented Nov 12, 2017

Could you have the chance to check the PR Michael?

@mredig
Copy link
Owner

mredig commented Nov 12, 2017

I am incredibly sorry this has taken so long!

If I'm understanding what you are attempting to do correctly, I think the functionality already exists... mostly.

When using a sequence, there is a property on the SGG_Spine object called currentAnimationSequence - it is a read only property. There may be cases where you wouldn't want to modify it directly from an object instance, so I wouldn't suggest removing that. However, you might want to instead add a function that inserts the name of the animation you want to play at index 1, obviously checking that that is safe to do so - that way when the current animation finshes, your queued animation plays next.

Will this solve your use case? If not, can you elaborate the distinction of your code addition?

Additionally, given the nature of what you are trying to do, I would suggest modifying the documentation to clarify that the property queuedAnimation would be more aptly named defaultAnimation, but we cannot rename the property as it would break backward compatibility.

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

Successfully merging this pull request may close these issues.

2 participants