First let me explain my goal. I am trying to make an Animation that changes the properties of an ArcShape. An ArcShape's constructor takes two fields: startAngle and sweepAngle. I want to animate the sweepAngle so that it appears on screen as a continuously shrinking circle.
You can picture this animation by imagining PacMan. Imagine his mouth is closed. This animation would be akin to him opening his upper jaw more and more until there was no more PacMan.
Now… I have a couple of issues with implementing this. First, once an ArcShape is created, there are no built in methods of changing it’s sweepAngle. This brings me to my first question: Is there any way to override ArcShape and implement some setSweepAngle method? Or will I have to create a new ArcShape for each sweepAngle I wish to display?
Now on to the second issue… Assuming I found a solution to the first issue, how could I create this Animation? This is the gist of what I have now:
public class OpenPacman extends Animation {
public OpenPacman(float startAngle, float sweepAngle) {
mStartAngle = startAngle;
mSweepAngle = sweepAngle;
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
/* This represents the current sweepAngle */
float currAngle = mStartAngle + ((mSweepAngle - mStartAngle) * interpolatedTime);
//Now I need to update the ArcShape's sweepAngle to currAngle. But HOW?
}
}
I have found a solution. I have a class that extends
ViewWe’ll call thisPacmanI nested my customAnimationwithin thisPacmanclass. This allowed me to access themember variablesof thePacmanclass.Now when the custom animation updates the container classes
mCurrAngle,onDrawis automatically called, which draws the appropriateArcShape.