Pausing and Resuming an amination

  • Replies:2
Stephen Kong
  • Forum posts: 17

Apr 1, 2012, 4:43:54 PM via Website

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?

— modified on Apr 1, 2012, 4:55:25 PM

Reply
Eric McBride
  • Forum posts: 1,790

Apr 2, 2012, 3:39:09 PM via Website

Boah...you just blew my mind! Sounds like you need some developmental help. Have you tried posting your question on XDA Developers?

Reply