Coding the Animator
Add the members and a constructor to a new class called Animator.
class Animator {
private Rect mSourceRect;
private int mFrameCount;
private int mCurrentFrame;
private long mFrameTicker;
private int mFramePeriod;
private int mFrameWidth;
Animator(float frameHeight,
float frameWidth,
int frameCount,
int pixelsPerMetre) {
final int ANIM_FPS = 10;
this.mCurrentFrame = 0;
this.mFrameCount = frameCount;
this.mFrameWidth = (int)frameWidth * pixelsPerMetre;
frameHeight = frameHeight * pixelsPerMetre;
mSourceRect = new Rect(0, 0,
this.mFrameWidth,
(int)frameHeight);
mFramePeriod = 1000 / ANIM_FPS;
mFrameTicker = 0L;
}
}Let's look at all those variables one at a time.
- The
mSourceRectmember is aRectthat will hold the four corners of the frame to be animated. Put another way...