Stephen Kong
- Forum posts: 17
Apr 1, 2012, 4:43:54 PM via Website
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?
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
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.