• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Pausing and Resuming an amination

zollen

Newbie
Oct 11, 2011
21
0
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?
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones