Coding a Renderer
As with many of the classes in this chapter, Renderer
will be very similar to the earlier project, so we can zip through it and move on.
Create a new class called Renderer
then add the following members and constructor.
class Renderer { private Canvas mCanvas; private SurfaceHolder mSurfaceHolder; private Paint mPaint; // Here is our new camera private Camera mCamera; Renderer(SurfaceView sh, Point screenSize){ mSurfaceHolder = sh.getHolder(); mPaint = new Paint(); // Initialize the camera mCamera = new Camera(screenSize.x, screenSize.y); } }
The Renderer
has the Canvas
, SurfaceHolder
and Paint
instances as we have come to expect. It also has a Camera
instance called mCamera
. We at last get to code the Camera
class when we are done with Renderer
.
In the constructor the SurfaceHolder
, Paint
and Camera
instances are initialized.
Now add the getPixelsPerMetre
and draw
methods.
int getPixelsPerMetre(){ return mCamera...