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 mSourceRect member is a Rect that will hold the four corners of ...

Get Learning Java by Building Android Games - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.