X

Sign in

Forgotten your password?

... or login with Facebook:

Don't have an AndroidPIT account yet? Sign up
Android Forum » Android Developer Forum » Android Developer Forum » Pausing and Resuming an amination

Pausing and Resuming an amination

Pausing and Resuming an amination
created on Apr 1, 2012 4:43:54 PM — modified on Apr 1, 2012 4:55:25 PM
I have been writing a 2D action game using mostly Canvas, ObjectAnimator and Bitmap. I am trying to handle scenarios where the game could be paused and resume later (i.e. user initiated a pause command, or the game went back to background..etc).

It is understandable that ObjectAnimator would not support pause/resume functions because the class manages the begin value, end value and duration of the animation itself. What would be the best approach to implement a "illusion" of pause/resume on an ObjectAnimator animation even with the absent of such operations?

I have been thinking of the following work around:

when a pause operation is initiated..
Step 1. Calling ObjectAnimator.setTarget() for redirecting the animator to update an dummy object
*OR*
Step 1. Calling ObjectAnimator.setPropertyName() for redirecting the animator to update a dummy property of the same object.

Step 2. Calling ObjectAnimator.getCurrentPlayTime() for storing the current position of animation in time.

when a resume operation is initiated..
Step 1. Re-creating/Cloning the ObjectAnimator and manually set the current position of animation in time to this ObjectAnimator instance

Step 2. ObjectAnimator.start()

-------------
Here are my questions

1. Do you think this work around would work?
2. For the resume operation step #1, is that a way to reduce the cost creating an ObjectAnimator? Would the ObjectAnimator.clone() worked even the copied animator has already started?
Reply with quote Reply Link ±0     (0 votes)
RE: Pausing and Resuming an amination
created on Apr 2, 2012 3:39:09 PM
Boah...you just blew my mind! Sounds like you need some developmental help. Have you tried posting your question on XDA Developers?
Reply with quote Reply Link ±0     (0 votes)
RE: Pausing and Resuming an amination
created on Apr 4, 2012 4:14:44 AM
Have you tried specifying Keyframe and using just the last frame while your paused?

http://developer.android.com/reference/android/animation/Keyframe.html
Reply with quote Reply Link ±0     (0 votes)